Back PHP

How to Limit Character in The Post Title

WRITTEN BY ON 19 Apr 2011
12,593 VIEWS • SHARES
0 comments

Sometimes, You might want to automatically limit the length of post title in the main page. This little wordpress hack will allow you to limit the displayed post title by a defined number of characters on your blogs home page.

PHP

put the code in the function.php

for read more: http://www.dynamicwp.net/articles-and-tutorials/how-to-limit-character-in-the-post-title/

function titlelimitchar($title){
	if(strlen($title) > 55 && !(is_single()) && !(is_page())){
		$title = substr($title,0,55) . "..";
	}
	return $title;
}
add_filter( 'the_title', 'titlelimitchar' );

Join the discussion

Comments will be moderated and rel="nofollow" will be added to all links. You can wrap your coding with [code][/code] to make use of built-in syntax highlighter.