Hello,
I usually use this function to shorten my titles:
function the_title_shorten($len,$rep='...') {
$title = the_title('','',false);
$shortened_title = textLimit($title, $len, $rep);
print $shortened_title;
}
//shorten without cutting full words (Thank You Serzh 'http://us2.php.net/manual/en/function.substr.php#83585')
function textLimit($string, $length, $replacer) {
if(strlen($string) > $length)
return (preg_match('/^(.*)\W.*$/', substr($string, 0, $length+1), $matches) ? $matches[1] : substr($string, 0, $length)) . $replacer;
return $string;
}
However, I have one plugin which has this line of code:
<a href='" . get_permalink($post->ID) . "' title='". esc_attr($post->post_title) ."'>" . esc_html($post->post_title) ."</a>
How can I shorten the title of esc_html($post->post_title) ?
Thanks for your help !