logo

This is an old version of this answer!

Return to the current answer
Hey Devin,

Give this a try. Add the following code to the functions.php This filter is used by wp_trim_excerpt()


function new_excerpt_length($length) {
return 200;
}
add_filter('excerpt_length', 'new_excerpt_length');



---------------------------------------------
You could also do a complete new function on your own, by adding this to the functions.php

function custom_trim_excerpt($length) {
global $post;
$explicit_excerpt = $post->post_excerpt;
if ( '' == $explicit_excerpt ) {
$text = get_the_content('');
$text = apply_filters('the_content', $text);
$text = str_replace(']]>', ']]>', $text);
}
else {
$text = apply_filters('the_content', $explicit_excerpt);
}
$text = strip_shortcodes( $text ); // optional
$text = strip_tags($text);
$excerpt_length = $length;
$words = explode(' ', $text, $excerpt_length + 1);
if (count($words)> $excerpt_length) {
array_pop($words);
array_push($words, '[…]');
$text = implode(' ', $words);
$text = apply_filters('the_excerpt',$text);
}
return $text;
}

Then just call the function in your template files, where you want to show the excerpt, by adding
<?php echo custom_trim_excerpt(100); ?>

Sidd | 08/06/10 at 12:13pm

This is an old version of this answer!

Return to the current answer