WordPress.org

Support

Support » How-To and Troubleshooting » I cannot shorten title posts

I cannot shorten title posts

  • 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 !

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘I cannot shorten title posts’ is closed to new replies.