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?

1 Answer 1


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.

  • Thanks for the clarification and the much needed Homer Simpson moment.
    – Steve
    Nov 4, 2012 at 13:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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