Using WordPress ‘remove_filter()’ PHP function

The remove_filter() WordPress PHP function removes a callback function from a filter hook. This can be used to remove default functions attached to a specific filter hook and possibly replace them with a substitute.

Usage

remove_filter( $hook_name, $callback, $priority )

Example:

Input: remove_filter( 'the_content', 'wpautop' )

Parameters

  • $hook_name (string) - The filter hook to which the function to be removed is hooked.
  • $callback (callable|string|array) - The callback to be removed from running when the filter is applied. This function can be called unconditionally to speculatively remove a callback that may or may not exist.
  • $priority (int, optional) - The exact priority used when adding the original filter callback. Default: 10

More information

See WordPress Developer Resources: remove_filter()

Examples

Remove the wpautop filter

Remove the wpautop filter from the the_content hook.

remove_filter( 'the_content', 'wpautop' );

Remove capital_P_dangit filter from multiple hooks

Remove the capital_P_dangit filter from the_content, the_title, and comment_text hooks.

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

Remove a filter added from within a class

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') );

Remove a filter with a specific priority

Remove a filter with a specific priority. In this example, the priority is set to 20.

remove_filter( 'the_content', 'my_custom_function', 20 );

Remove a filter added by a plugin after it's added

You may need to prioritize 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.

add_action( 'plugins_loaded', 'my_remove_plugin_filters', 11 );

function my_remove_plugin_filters() {
    remove_filter( 'the_content', 'some_plugin_filter_function', 10 );
}