WordPress at a glance

remove_filter() WP 1.2.0

Removes a function from a specified filter hook.

This function can be used to remove default functions attached to a specific filter hook and possibly replace them with a substitute or to remove hooks that are added by plugins but interfere (conflict) with current code.

IMPORTANT: When removing a hook, the priority ($priority) must match the one that was set when the hook was created. If it does not match, you will not see any warnings about this - the function will simply return false.

Notes
  • It's impossible to remove a filter before it has been added!
  • If you want to delete a hook that was created inside a class, then you need to pass this instance of the class from which the hook was created.
Is the basis for: remove_action()
✈ 1 time = 0.s = speed of light | 50000 times = 0.06s = speed of light

No Hooks.

Return

true/false. Whether the function existed before it was removed.

Usage

remove_filter( $tag, $function_to_remove, $priority );
$tag(string) (required)
The filter hook to which the function to be removed is hooked.
$function_to_remove(callable) (required)
The name of the function which should be removed.
$priority(int)
The priority of the function.
Default: 10

Examples

#1 Remove a filter wpautop from hook the_content

remove_filter( 'the_content', 'wpautop' );

#2 Remove a filter capital_P_dangit from hooks 'the_content', 'the_title', 'comment_text'

foreach ( array( 'the_content', 'the_title', 'comment_text' ) as $hook )
	remove_filter( $hook, 'capital_P_dangit' );

#3 Remove a filter added from PHP class

If a filter has been added from within a class, removing it will require accessing the class variable:

global $my_class;
remove_filter( 'the_content', array( $my_class, 'class_filter_function') );

To get a better grasp of removing hooks that use class method, see the description of remove_action()

Code of remove filter: wp-includes/plugin.php WP 5.2.1

<?php
function remove_filter( $tag, $function_to_remove, $priority = 10 ) {
	global $wp_filter;

	$r = false;
	if ( isset( $wp_filter[ $tag ] ) ) {
		$r = $wp_filter[ $tag ]->remove_filter( $tag, $function_to_remove, $priority );
		if ( ! $wp_filter[ $tag ]->callbacks ) {
			unset( $wp_filter[ $tag ] );
		}
	}

	return $r;
}

Related Functions

From tag: Filters (hooks)

More from category: Hooks (actions, filters)

No comments
    Hello, !     Log In . Register