Limit the size of the post excerpt without using a plugin

October 26, 2008

Edit your single.php file and replace the the_excerpt() function by the following code: <?php $len = 50; //Number of words to display in excerpt $newExcerpt = substr($post->post_excerpt, 0, $len); //truncate excerpt according to $len if(strlen($newExcerpt) < strlen($post->post_excerpt)) { $newExcerpt = $newExcerpt."[...]"; } echo "<p>".$newExcerpt."</p>"; //finally display excerpt ?> Let’s have a look at the code: First, we define the desired number of words for the post excerpt. It is defined... [Read the full story]