How to Limit Character in The Post Title

One of the most important elements in your blog’s web design is the post title. It reaches out and grabs people’s attention. It informs them of what the post is about, hopefully.

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.

The code snippet below should be placed somewhere within your wordpress themes functions.php. If your wordpress theme does not have a functions.php file simply create one with your favourite text editor and place it in your wordpress themes folder.

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

This code will limit post title in the homepage to 55 characters. If the title is more than 55 chars, it will be cut off and “..” will be added in the end of title.

Hope this code help :)

8 Comments to “How to Limit Character in The Post Title”

Add Comments (+)

  1. Thanks for this useful code. This will help regarding the Post Title SEO.

  2. Toni says:

    Awesome post sir! I was wondering if there’s a similar code snippet that will work with themes that don not have the excerpt tag available? So in other words shortening whats displayed in the excerpt.

  3. 3x7 says:

    Will this permanently change all posts already stored? or just display limited titles?
    I’m looking for such solution that will permanently change all titles to 30 characters and add trailing “…” at the end…

  4. angelazhang says:

    Thanks a lot for posting this tutorial. It worked like a charm. However, how do I keep post title (tooltip one) to its original value?
    Any help would be greatly appreciated.
    Thank you :D

  5. Dev Baisoya says:

    Will it work on Blogger? Please tell me, because I want to do it on my Blogger blog…


  1. やみろぐ。» Blog Archive » 在functions.php增設博客自訂代碼
  2. WordPress のよくあるカスタマイズコード functions.php 多め « 俺のブログ

Leave a Reply


Amazingly Beautiful WordPress Themes