Excerpt is the ‘post summary’ showing limited information about the post content on the homepage of the blog. By default the standard WordPress excerpt displays 55 words. You can control the excerpt word length by using the below code snippet.
Add this code into your theme’s functions.php file.
[php]
function ctr_excerpt_length($string, $wordLimit) {
$words = explode(‘ ‘, $string);
return implode( ‘ ‘, array_slice($words, 0, $wordLimit) );
}
[/php]
Add following code in the theme pages where you want to limit the excerpt word length (commonly used in theme’s homepage and category archive page).
[php]
/** Change 25 to Your Desired Length for Excerpt */
echo ctr_excerpt_length(get_the_excerpt(), ’25’);
[/php]
You may also be interested in our other articles on remove feeds form wordpress, allow more tags in comments, disable auto generated paragraph tags and nofollow wordpress tag cloud.
Leave a Reply