[wp-hackers] filter the_exceprt

Daniel Cameron dan at sproutventure.com
Mon Jan 12 00:51:41 GMT 2009


Hey guys,
Can someone help me here. I've written a filter but it seems like it's not
working correctly and I'm at my wits end.

function sp_excerpt($text) { // Fakes an excerpt if needed
if ( '' == $text ) {
$text = get_the_content('');
 $text = strip_shortcodes( $text );
 $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, 'Read More');
$text = implode(' ', $words);
}
}
return $text;
}
// Add filter to the_content
add_filter('the_excerpt', 'sp_excerpt');


Any help would be appreciated.

I'm basically trying to get rid of that horrible [...] ellipses forces on
the_exceprt, so maybe you have another solution (without a plugin).

Thanks.


More information about the wp-hackers mailing list