Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I was hoping to process the_excerpt just like one would with the_content, but no such luck.

How can I pass the excerpts of a Posts Page, through my plugin? I've tried variations on this:

add_filter('the_excerpt', 'my_function');

But alas, no go. Suggestions?

EDIT: It looks like my filter call won't work when called from within another function, but it DOES work if it's at the same level of the function I'm calling, like so:

add_filter('the_excerpt', 'my_filter');

function my_filter($content) {
    die('hello');
}

Any ideas why this is?

share|improve this question
    
you can filter the excerpt that way, what does your function look like? –  Milo Oct 6 '11 at 4:49
    
Well actually it's quite a complex series of functions, but I already have them running just fine on the_content, the_title, wp_title, and wp_head so I figured if the_excerpt was valid, it should just work. Maybe it has to do with the fact that I'm looking at the static posts page? Do the excerpts on that particular page behave differently? –  Jonathan van Clute Oct 6 '11 at 4:58
    
they all use the same function, the_excerpt just applies default filters to get_the_excerpt which can also be filtered. use has_filter and make sure nothing is removing filters from the_excerpt. try just a simple function and throw a die() in there or something. –  Milo Oct 6 '11 at 5:04
    
Just did exactly that... tried a super simple function "die('hello');" and it does nothing. Not sure what's amiss here... –  Jonathan van Clute Oct 6 '11 at 5:13
    
what do you see if you add global $wp_filter; print_r($wp_filter['the_excerpt']); in your template? –  Milo Oct 6 '11 at 5:21
show 3 more comments

1 Answer

use the filter get_the_excerpt. Look at line no. 250 here, they are using the_excerpt internally on the function get_the_excerpt(), and in this function on line no. 272, they're applying the filter get_the_excerpt on the actual excerpt. Hence,

add_filter('get_the_excerpt', 'exc');

function exc($param) {

    return "Whew !".$param;
}

is the way to go if you want to filter excerpts!

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.