Saturday, April 23, 2011

Display wordpress post titles with a custom length

Display wordpress post titles with a custom length

Display wordpress post titles with a custom length

 If you want to  display only the first X characters of your wordpress post title, I display here some hack for that.

 The first thing to do is to create the function. Open your functions.php file and paste this code:

  function ODD_title($char) {
         $title = get_the_title($post->ID);
         $title = substr($title,0,$char);
         echo $title;
 }

 Now, you use the function on your wordpress theme files. Just pass how many characters you want to display as a parameter. In the following example, only the first 30 chars of the title will be displayed:

ODD_title(20);

So with the following code you can display wordpress post titles with a custom length

No comments:

Post a Comment

I just got my #domain @BigRock. Get upto 25% off with my personalized coupon link Get upto 25% off