Modify length of word in the_excerpt function wordpress

Default length of words in the_excerpt function wordpress is 55 words . How to modify it ? when you think it is too long or you want more words to display it ?

– Adding this function in wp-includes/formatting.php

function string_limit_words($string, $word_limit)
{
$words = explode(‘ ‘, $string, ($word_limit + 1));
if(count($words) > $word_limit)
array_pop($words);
return implode(‘ ‘, $words);
}

– add this line in templates page that you want to display the_excerpt

<?php $excerpt = get_the_excerpt(); echo string_limit_words($excerpt, n); ?>

: number of word that you want to display .

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s