WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I understand that using add_filter() or remove_filter() directly within a themes' functions.php would make the changes global across the theme unless you override them elsewhere. But believe this is a result of WordPress initialization.

add_filter( $tag, $function_to_add, $priority, $accepted_args );

However if a call to add_filter() or remove_filter() is made within a function or class:

function example(){
    add_filter( $tag, $function_to_add, $priority, $accepted_args );

What is the scope and persistence of the change?

share|improve this question
up vote 0 down vote accepted

It is always global. add_filter() and add_action() are just wrapper for the global variable $wp_filter. So it doesn’t matter where the function is called.

The same is true for apply_filters(), apply_filters_ref_array(), do_action_ref_array() and do_action(): they work in the global namespace, that’s the reason why the callback handlers (functions or methods) have to be public. A protected class method cannot be called from the global scope.

share|improve this answer
Thanks for the clarification and the much needed Homer Simpson moment. – Stephen Nov 4 '12 at 13:25

Your Answer


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.