[wp-hackers] Is there a post content action hook?

Austin Matzko if.website at gmail.com
Tue Oct 7 16:28:32 GMT 2008


On Tue, Oct 7, 2008 at 11:51 AM, Michael Harris <harrismw at huridocs.org> wrote:
> I wish to display information before or after a post using a plugin,
> and it is not feasible to use themes, due to the fact that the plugin
> is meant to be generic (and not tied to one theme).
>
> "the_content filter gets applied to the content before it trims off
> the end. It has to do this, because the raw content may contain things
> that control formatting or replacement of words and such and you don't
> want those to be bypassed just because you're getting an excerpt." -
> http://wordpress.org/support/topic/115198
>
> This has been driving me barmy. Thanks.

Here's how you can get around this:

function content_changing_function($text) {
  [... change content stuff here ...]
}
add_filter('get_the_excerpt', create_function('$t',
'remove_filter("the_content", "content_changing_function"); return
$t;'), 9);
add_filter('get_the_excerpt', create_function('$t',
'add_filter("the_content", "content_changing_function"); return $t;'),
11);
add_filter('the_content', 'content_changing_function');

This removes content_changing_function as a callback for "the_content"
right before "the_content" is applied to the excerpt.


More information about the wp-hackers mailing list