Otto | 20 Jul 00:26 2011

Re: filter the_content without affecting the_excerpt

The purpose of wp_trim_excerpt is to create an artificial excerpt if
one doesn't exist for the post. So it applies the content filters to
the content, then trims it down to create the excerpt.If there is an
explicit excerpt on the post, then the content filters will not be
applied to that, nor will the content even get pulled.

So if you're adding something to the beginning of the content, then it
will be in the created excerpt. This is by design.

If you don't want it to do that, use a shortcode to insert your
content. Shortcodes get stripped from auto-created excerpts.

-Otto

On Tue, Jul 19, 2011 at 5:10 PM, Philip Walton <philip <at> philipwalton.com> wrote:
> So, I've spent some time digging through the source, and it appears the
> wp_trim_excerpt() function applies 'the_content' filters to the excerpt by
> default. And it looks like there's no getting around it.
>
> Can someone please explain the rational behind not differentiating the two?
> Why should I be forced to apply my content filters to my excerpts as well?
>
>
> On 7/19/11 12:38 PM, Philip Walton wrote:
>>
>> In my theme I'm adding a filter to "the_content" to insert social sharing
>> buttons at the beginning of each post, but then when I call the_excert() the
>> text of those buttons is showing up.
>>
>> I know I can just write another filter on "get_the_excerpt" to remove
>> them, but that just seems wrong.
>>
>> Is there a way to filter the_content without affecting the_excerpt?
>
> _______________________________________________
> wp-hackers mailing list
> wp-hackers <at> lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>

Gmane