WordPress.org

Ready to get started?Download WordPress

Codex

Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/remove filter

Description

This function removes a function attached to a specified filter hook. This method can be used to remove default functions attached to a specific filter hook and possibly replace them with a substitute. See also remove_action(), add_filter() and add_action().

Important: To remove a hook, the $function_to_remove and $priority arguments must match when the hook was added. This goes for both filters and actions. No warning will be given on removal failure.

Usage

<?php remove_filter$tag$function_to_remove$priority ); ?>

Parameters

$tag
(string) (required) The action hook to which the function to be removed is hooked.
Default: None
$function_to_remove
(callback) (required) The callback for the function which should be removed.
Default: None
$priority
(int) (optional) The priority of the function (as defined when the function was originally hooked).
Default: 10

Return

(boolean
Whether the function is removed.
  • True - The function was successfully removed.
  • False - The function could not be removed.

Example

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

If a filter has been added from within a class, for example by a plugin, removing it will require accessing the class variable.

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

It is also worth noting that you may need to prioritise the removal of the filter to a hook that occurs after the filter is added. You cannot successfully remove the filter before it has been added.

Notes

When using filters passed with objects, you most often need to pass the exact same object back to the remove filter call, not just another instance of that object.(read _wp_filter_build_unique_id() for the gory details)

Change Log

  • Since: 1.2.0

Source File

remove_filter() is located in wp-includes/plugin.php.

Related

Filters: has_filter(), add_filter(), apply_filters(), current_filter(), merge_filters(), remove_filter(), remove_all_filters()

See also index of Function Reference and index of Template Tags.