Support » Fixing WordPress » How do I truncate single posts?

Viewing 2 replies - 1 through 2 (of 2 total)
  • you don’t.

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

    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:

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How do I truncate single posts?’ is closed to new replies.