Do you ever got an issue to fit your blog post titles in limited width space. Or if every your client asks you to display only first 100 characters of the blog posts title. If yes then you are at right place, as in this post I am sharing a best trick to truncate post title in wordpress blog, without using any plugin.

To implement truncated post title you simply have to locate the file containing post title. This all depends on the WordPress theme you are using on your site, but most provably the title code will located in index.php of your current activated theme folder.

Implementing Truncated Post Title

1. Simply open index.php from your current activated theme

2. Search for anchor tag with post title. Code might look something like this –
<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a>. Or you can simply search for <a href="<?php the_title(); ?>

3. Replace complete anchor tag with the below code

<a href="<?php the_permalink() ?>">
<?php
$thetitle = $post->post_title; 
$getTitlelength = strlen($thetitle);
$titlelength = 100;
echo substr($thetitle, 0, $titlelength);
if ($getTitlelength > $titlelength) echo "...";
?>
</a>

Just don’t forget to adjust the character limit in the above code as per your requirement, as in above code I have assigned “100” as a character limit. So the above code will going to display first 100 characters of you blog post title following with “…”

You can also directly place this code in any of the theme file where you want to display truncated post title.

Related posts:


  • Poo

    Hey Amit,
    i must say you ar edoing an amazing job by help others which are novice to the blog world with your easy to understand and implement methods.
    i am working on creating my blog an these tips are deifinitely going to help me out..

  • Nikia

    Amit this is awesome – how did you figure this out? I’m just glad it took me so little time to find it. Little tidbits like these are so useful because a lot of how-to articles miss the small things like this. Thanks :-)

  • Manish

    Hey Amit

    Though a small change, such tips saves you time.

    Thanks