How do I truncate single posts? (3 posts)

  1. jooames
    Posted 4 years ago #

    How do I truncate single posts?

  2. Michael
    Part-Time Forum Moderator
    Posted 4 years ago #

    you don't.

    if you would, how would you ever get the full post to show?

  3. JsonB123
    Posted 4 years ago #

    While alchymyth makes a good point, because single posts is supposed to be for a full view...you could add this to your functions.php file:

    function limit_text($text, $limit) {
    	if (strlen($text) > $limit) {
    		$words = str_word_count($text, 2);
    		$pos = array_keys($words);
    		$text = substr($text, 0, $pos[$limit]) . '...';
    	return $text;

    And then run your content through through that function like so:
    limit_text(the_content(), 5); // 5 being the amount of words you'd want to have before truncation.

    However, there are better ways to do this, including allowing the user to truncate normally and calling the_excerpt().

    You can see more on how to do these things here: http://wordpress.org/support/topic/truncating-the-content-output?replies=5

Topic Closed

This topic has been closed to new replies.

About this Topic