[wp-hackers] RE: wp-hackers Digest, Vol 38, Issue 110

Alakhnor alakhnor at wanadoo.fr
Wed Mar 26 19:30:56 GMT 2008


> ------------------------------
> 
> Message: 7
> Date: Tue, 25 Mar 2008 09:44:55 -0500
> From: Otto <otto at ottodestruct.com>
> Subject: Re: [wp-hackers] the_excerpt filters
> To: wp-hackers at lists.automattic.com
> Message-ID:
> 	<161617690803250744v378f3fefs5155e2aef1108b27 at mail.gmail.com>
> Content-Type: text/plain; charset=ISO-8859-1
> 
> wp_trim_excerpt creates an excerpt from the content, but only if
> there's not a manually defined excerpt. It has to get the content and
> apply the content filters so that it has the content to build the
> excerpt from.
> 
> 
> On Tue, Mar 25, 2008 at 1:42 AM, Alakhnor <alakhnor at wanadoo.fr> wrote:
> > Is there any good reason why the "get_the_excerpt" filter
> (wp_trim_excerpt)
> >  calls the_content filter?
> >  This means you cannot filter anything before the content is actually
> built.
> >
> >  Alakhnor
> >
> >
> >  _______________________________________________
> >  wp-hackers mailing list
> >  wp-hackers at lists.automattic.com
> >  http://lists.automattic.com/mailman/listinfo/wp-hackers
> >
Yes, but it could be done in differentiating get_the_content('') and
the_content filters, probably by adding a filter in between, in
wp_trim_excerpt.
	function wp_trim_excerpt($text) { // Fakes an excerpt if needed
		global $post;
		if ( '' == $text ) {
			$text = get_the_content('');
			$text = apply_filters('wp_trim_excerpt', $text);
			$text = apply_filters('the_content', $text);
			$text = str_replace(']]>', ']]&gt;', $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;
	}
Many plugins use 'the_content' filter. But, let's say you want to replace a
tag like <youtube> and gain control over how it's done in the excerpt, you
have to use workarounds to achieve it.






More information about the wp-hackers mailing list