Easily display post titles with a custom length

February 17th, 2011 at 12:16am Jason 59 views

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 can use the function on your theme files. Just pass how many characters you want to display as a parameter. In the following exemple, only the first 20 chars of the title will be displayed:

<?php ODD_title(20); ?>

via: http://www.wprecipes.com/easily-display-post-titles-with-a-custom-length

Entry Filed under: WordPress Tagged with:

Share This Post Share This Post SubscribePrint This Post Print This PostSave As PDF Save As PDF

Related Posts Hot Posts Hot Comments Hot Tags

      Leave a Comment

      Required

      Required, hidden

      Some HTML allowed:
      <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

      Trackback this post  |  Subscribe to the comments via RSS Feed


      Calendar

      February 2011
      MTWTFSS
      « Jan Mar »
       123456
      78910111213
      14151617181920
      21222324252627
      28 

      Sponsors

      Most Recent Posts