WP-Tips: Adjusting Excerpt Display Count

Jun 9th, 2008 | By dikiem | Category:WordPress Tips and Hack | 1 comment | 67 views |

In wordpress, the commonly used tag to show summary of an article or post is <?php the_excerpt(); ?>. By default, if you don’t provide an excerpt, wordpress will use the first 55 words in the article as the excerpt.

What if you want to have more or less than 55 words, how is this accomplished?

You can by easily editing the file ./wp-includes/formatting.php

function wp_trim_excerpt($text) { // Fakes an excerpt if needed
if ( ” == $text ) {
$text = get_the_content(”);
$text = apply_filters(’the_content’, $text);
$text = str_replace(’]]>’, ‘]]>’, $text);
$text = strip_tags($text);
$excerpt_length = 55;
$words = explode(’ ‘, $text, $excerpt_length + 1);
if (count($words) > $excerpt_length) {
array_pop($words);
array_push($words, ‘[...]‘);
$text = implode(’ ‘, $words);
}
}
return $text;
}

In the above code, noticed in BOLD BLUE. By changing the default number of 55 higher or lower, that ultimately control how many words the excerpt tag will display.



1 comment | 67 views

Tags: ,



One comment
Leave a comment »

  1. Thanks, was looking for this for the last hour!

Leave Comment