W3cubDocs

/WordPress

remove_filter( string $hook_name, callable|string|array $callback, int $priority = 10 ): bool

Removes a callback function from a filter hook.

Description

This can be used to remove default functions attached to a specific filter hook and possibly replace them with a substitute.

To remove a hook, the $callback 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.

Parameters

$hook_namestringrequired
The filter hook to which the function to be removed is hooked.
$callbackcallable|string|arrayrequired
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.
$priorityintoptional
The exact priority used when adding the original filter callback.

Default:10

Return

bool Whether the function existed before it was removed.

Source

function remove_filter( $hook_name, $callback, $priority = 10 ) {
	global $wp_filter;

	$r = false;

	if ( isset( $wp_filter[ $hook_name ] ) ) {
		$r = $wp_filter[ $hook_name ]->remove_filter( $hook_name, $callback, $priority );

		if ( ! $wp_filter[ $hook_name ]->callbacks ) {
			unset( $wp_filter[ $hook_name ] );
		}
	}

	return $r;
}

Changelog

Version Description
1.2.0 Introduced.

© 2003–2024 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/remove_filter