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.

If a plugin modified one of wp's filters by "add_filter", and I want to discard the modification and modify the wp's filter by my own codes. Should I remove the plugin's filter before I add my own filter?

share|improve this question
1  
To replace a filter you should use remove_filter first –  tamilsweet Jun 6 '12 at 0:28
add comment

1 Answer 1

up vote 2 down vote accepted

Yes, you need to remove it first and then add your one. You can do it by calling remove_filter function like this:

remove_filter( 'wp_core_filter_hook', 'wp_core_filter_hook_handler', 10 );

Pay attention at third parameter passed to function: it is priority, it should be the same as defined when the function was originally hooked, otherwise the filter hook won't be removed.

If you want to remove all hook handlers, you can call remove_all_filters function:

remove_all_filter( 'wp_core_filter_hook' );
// or with priority
remove_all_filter( 'wp_core_filter_hook', 10 );

This function takes two parameters: filter name and priority (optional). If you pass priority then all handlers with specified priority will be removed.

And finally if you want to check if any filter has been registered for a hook, use function has_filter. It takes two parameters: filter name and function name (optional).

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.