WP_Hook::remove_filter() WordPress Method

The WP_Hook::remove_filter() method is used to remove a filter from a WordPress hook. This is useful if you want to remove a filter that you have added with the add_filter() method.

WP_Hook::remove_filter( string $hook_name, callable|string|array $callback, int $priority ) #

Removes a callback function from a filter hook.


Parameters

$hook_name

(string)(Required)The filter hook to which the function to be removed is hooked.

$callback

(callable|string|array)(Required)The callback to be removed from running when the filter is applied. This method can be called unconditionally to speculatively remove a callback that may or may not exist.

$priority

(int)(Required)The exact priority used when adding the original filter callback.


Top ↑

Return

(bool) Whether the callback existed before it was removed.


Top ↑

Source

File: wp-includes/class-wp-hook.php

	public function remove_filter( $hook_name, $callback, $priority ) {
		$function_key = _wp_filter_build_unique_id( $hook_name, $callback, $priority );

		$exists = isset( $this->callbacks[ $priority ][ $function_key ] );

		if ( $exists ) {
			unset( $this->callbacks[ $priority ][ $function_key ] );

			if ( ! $this->callbacks[ $priority ] ) {
				unset( $this->callbacks[ $priority ] );

				if ( $this->nesting_level > 0 ) {
					$this->resort_active_iterations();
				}
			}
		}

		return $exists;
	}


Top ↑

Changelog

Changelog
VersionDescription
4.7.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.