[wp-hackers] filter the_content without affecting the_excerpt

Philip Walton philip at philipwalton.com
Tue Jul 19 23:24:45 UTC 2011

I suppose a relatively painless solution is to create your own 
the_content() function and add another filter yourself that the_excert() 
won't apply

For example:

// calls the_content() and adds an extra filter which the_excerpt() 
won't apply
function pw_the_content($more_link_text = null, $stripteaser = 0) {
     $content = get_the_content($more_link_text, $stripteaser);
     $content = apply_filters('the_content', $content);
     $content = str_replace(']]>', ']]>', $content);

     // apply the filter 'post_the_content'
     $content = apply_filters('post_the_content', $content);

     echo $content;

Then use call pw_the_content() instead of the_content() and you should 
be fine.

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?

More information about the wp-hackers mailing list