WordPress Truncated Post Title

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:

Author:

is co-founder and author of tips4developer. By profession he is a WordPress and Joomla developer.


Subscribe to email feed

  • RSS
  • Delicious
  • Digg
  • Facebook
  • Twitter
  • Linkedin

Joomla – Allowing

Recently I got an requirement to add multiple email ID’s ...

WordPress - Controll

Page Lists Plus is one of the most use full ...

IE compatible mode

I noticed most of the web developers and designers hate ...

Adding PayPal Donate

Adding PayPal Donate Button in WordPress Post and Page are ...

Multi Browsers CSS H

Here I am sharing few of the very useful multi ...

Joomla – Allowing

Recently I got an requirement to add multiple email ID’s ...

Virtuemart – Setti

In my last project I got a requirement from my ...

3 Best Security Ext

Joomla is one of the fastest growing and best CMS ...

Joomla Conditional S

With the help of Joomla conditional statements you will able ...

Virtuemart - Special

Here I am sharing the virtuemart code snippet to display ...