How To Set The Limit Of Words In the_excerpt In WordPress

Posted by

Hi,

Many of the wordpress user wants to set the summary limit in the_excerpt. We can do it simply by adding the function:

function excerpt($num)
{
$limit = $num+1;
$excerpt = explode(‘ ‘, get_the_excerpt(), $limit);
array_pop($excerpt);
$excerpt = implode(” “,$excerpt).”…”;
echo $excerpt;
}

Add this function in function.php file of your theme. Now, edit the index.php file of your theme and find this:

Find:
the_excerpt()

Replace with:
<? php excerpt(’25’); ?>

This will set to 25 words in the excerpt summary. You can modify it according to your requirement.

Thanks,

Shane G.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.