has_filter( string $hook_name, callable|false $callback = false )

Checks if any filter has been registered for a hook.

Description Description

When using the $callback argument, this function may return a non-boolean value that evaluates to false (e.g. 0), so use the === operator for testing the return value.

Top ↑

Parameters Parameters


(string) (Required) The name of the filter hook.


(callable|false) (Optional) The callback to check for.

Default value: false

Top ↑

Return Return

(bool|int) If $callback is omitted, returns boolean for whether the hook has anything registered. When checking a specific function, the priority of that hook is returned, or false if the function is not attached.

Top ↑

Source Source

File: wp-includes/plugin.php

function has_filter( $hook_name, $callback = false ) {
	global $wp_filter;

	if ( ! isset( $wp_filter[ $hook_name ] ) ) {
		return false;

	return $wp_filter[ $hook_name ]->has_filter( $hook_name, $callback );

Top ↑

Changelog Changelog

Version Description
2.5.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

  1. Skip to note 2 content

    add_filter() calls the same _wp_filter_build_unique_id() function and re-assigns the method/function parameter to the index array.

    It is very likely that calling add_filter() with the same parameter list is faster than first checking if the method/function is already registered with has_filter( , ) before adding it with add_filter( , );

    I am guessing the best use-case for has_filter() is to check if a filter has ANY registered methods versus checking that a specific method exists prior to re-registering it with add_filter().

Top ↑

You must log in before being able to contribute a note or feedback.