[wp-hackers] Re: filter the_exceprt

Daniel Cameron dan at sproutventure.com
Mon Jan 12 04:39:33 GMT 2009


>
>
> add_filter('get_the_excerpt', 'sp_excerpt', 1, 2);
> 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;
> }
>
>

Turns out this does work, I just placed did a bone-headed move and placed
the add_filter at the top instead of the bottom--where it needs to be to
initiate.

A string replace is a good idea, I originally had something very similar but
I just reminded myself I need to have that "read more" link. So hopefully
I'll get there with the above code.

Thanks again.


More information about the wp-hackers mailing list