A WordPress-centric search engine for devs and theme authors

apply_filters ›

apply_filters ( $tag, $value )
Parameters: (3)
  • (string) $tag The name of the filter hook.
    Required: Yes
  • (mixed) $value The value to filter.
    Required: Yes
  • (mixed) ...$args Additional parameters to pass to the callback functions.
    Required: Yes
  • (mixed) The filtered value after all hooked functions are applied to it.
Defined at:

Calls the callback functions that have been added to a filter hook.

The callback functions attached to the filter hook are invoked by calling this function. This function can be used to create a new filter hook by simply calling this function with the name of the new hook specified using the $tag parameter.

The function also allows for multiple additional arguments to be passed to hooks.

Example usage:

// The filter callback function
function example_callback( $string, $arg1, $arg2 ) {
    // (maybe) modify $string
    return $string;
add_filter( 'example_filter', 'example_callback', 10, 3 );

  Apply the filters by calling the 'example_callback()' function that's
  hooked onto example_filter above.
  - 'example_filter' is the filter hook
  - 'filter me' is the value being filtered
 * - $arg1 and $arg2 are the additional arguments passed to the callback.
$value = apply_filters( 'example_filter', 'filter me', $arg1, $arg2 );


function apply_filters( $tag, $value ) {
	global $wp_filter, $wp_current_filter;

	$args = func_get_args();

	// Do 'all' actions first.
	if ( isset( $wp_filter['all'] ) ) {
		$wp_current_filter[] = $tag;
		_wp_call_all_hook( $args );

	if ( ! isset( $wp_filter[ $tag ] ) ) {
		if ( isset( $wp_filter['all'] ) ) {
			array_pop( $wp_current_filter );
		return $value;

	if ( ! isset( $wp_filter['all'] ) ) {
		$wp_current_filter[] = $tag;

	// Don't pass the tag name to WP_Hook.
	array_shift( $args );

	$filtered = $wp_filter[ $tag ]->apply_filters( $value, $args );

	array_pop( $wp_current_filter );

	return $filtered;