WordPress.org

Ready to get started?Download WordPress

Forums

I cannot shorten title posts (3 posts)

  1. evo252
    Member
    Posted 3 years ago #

    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 !

  2. evo252
    Member
    Posted 3 years ago #

    Nobody has an idea ?? I'm blocked on this step...:/

  3. doc4
    Member
    Posted 2 years ago #

    evo252,

    Wish I would have seen this sooner. Here are five ways to shorten the post title. Maybe this will help someone out there.

    http://www.doc4design.com/articles/wordpress-5ways-shorten-titles/

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags