Support » Fixing WordPress » How do I truncate titles?

  • Resolved FofR


    Titles are often too large for my layout and I’d like to make them smaller. The title output is given by “the_title( )” which I can’t truncate using the usual PHP function and I can’t seem to pass the contents of the_title to another string and then truncate that.

    Any help?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Les Bessant


    keeper of the Tiggers

    How about get_the_title()? That should return the value rather than echo it…

    There’s a filter hook for titles called ‘the_title’. That means all you need is to adapt a truncating PHP function, like the one here:
    and add it to the filter, like so:


    Try this code to truncate to the length you want:

    $tit = the_title('','',FALSE);
    echo substr($tit, 0, 51);
    if (strlen($tit) > 51) echo " ...";

    Change the numbers 51 to whatever length you want.

    Thank you, a combination of get_the_title() and jbbrwcky’s solution worked.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How do I truncate titles?’ is closed to new replies.