Support » Fixing WordPress » Post title char count?

  • Is ther a way to limit the number of letters in the post title. on my index.php it looks so bad when the title takes up 2 lines so can it be cut off at a certain point?

Viewing 4 replies - 1 through 4 (of 4 total)
  • heh. I ran into this same problem when I redesigned my front page. Long post titles wrapped to the second line causing that content block to drop out of alignment with respect to the others.

    The fix is simple enough – create a new function then call it in whatever template file you want.

    Add this to your theme’s functions.php …

    function trim_title() {
    $title = get_the_title();
    $limit = "x";
    if(strlen($title) <= $limit) {
    echo $title;
    } else {
    $title = substr($title, 0, $limit) . $pad;
    echo $title;

    Adjust the line $limit = "x"; to whatever you want. (say 20 for example)

    Then look in the appropriate template file for the_title() and replace with your new function trim_title() If your post title is more than the limit you specified it will trim it to that specification. If it is less it will do nothing.

    Thanks a ton 🙂

    thats a perfect solution. thanks a lot.

    Great exactly what i was looking for and had the same problem as LenK.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Post title char count?’ is closed to new replies.