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?
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: http://www.the-art-of-web.com/php/truncate/
and add it to the filter, like so:
add_filter('the_title','some_truncating_function');
Try this code to truncate to the length you want:
<?php
$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.