How to Limit WordPress Excerpt Number of Words

The default excerpt length is 55 words but you can control the number of words by doing the following:

1. Go to functions.php and paste the following code:

/* ********************
* Limit post excerpts. Within theme files used as
* print string_limit_words(get_the_excerpt(), 20);
******************************************************************** */
function string_limit_words($string, $word_limit) {
$words = explode(' ', $string, ($word_limit + 1));
if(count($words) > $word_limit)
return implode(' ', $words);

2. On the page where you want to show excerpt, paste the following:

<?php echo limit_words(get_the_excerpt(), '41'); ?>

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s