How to use the_excerpt in a filter hook?

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:

Read More
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?

Related posts

Leave a Reply

1 comment

  1. 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!