WordPress.org

Ready to get started?Download WordPress

Codex

Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/apply filters

Description

Call the functions added to a filter hook. See the Plugin API for a list of filter hooks.

The callback functions attached to filter hook $tag 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.

Usage

 <?php apply_filters$tag$value$var ... ); ?> 

Parameters

$tag
(string) (required) The name of the filter hook.
Default: None
$value
(mixed) (required) The value which can be modified by filters hooked to $tag
Default: None
$var
(mixed) (optional) One or more additional variables passed to the filter functions. You can use this parameter in your function but it will not be returned. This parameter is available since Version 1.5.1.
Default: None

Return

(mixed
The result of $value after all hooked functions are applied to it.

Note: The type of return should be the same as the type of $value: a string or an array, for example.

Examples

Echo after Filtering

echo apply_filters( $tag, $value );

Get Filtered

$myvar = apply_filters( $tag, $value );

Additional Filter Arguments

$myvar = apply_filters( $tag, $value, $param, $otherparam );
For example:
$myvar = apply_filters( 'example_filter', 'filter me', 'arg1', 'arg2 ');

With the_title filter

$my_custom_title = apply_filters('the_title', '  My Custom Title (tm)  ');

$my_custom_title will now contain 'My Custom Title ™', since the_title filter applies wptexturize() and trim(), among others.

Notes

Change Log

  • Since: 0.71

Source File

apply_filters() is located in wp-includes/plugin.php.

Related

Filters: has_filter(), add_filter(), apply_filters(), current_filter(), merge_filters(), remove_filter(), remove_all_filters()

See also index of Function Reference and index of Template Tags.