Hook a function or method to a specific filter action.

WordPress offers filter hooks to allow plugins to modify various types of internal data at runtime.

A plugin can modify data by binding a callback to a filter hook. When the filter is later applied, each bound callback is run in order of priority, and given the opportunity to modify a value by returning a new value.

The following example shows how a callback function is bound to a filter hook. Note that $example is passed to the callback, (maybe) modified, then returned:

function example_callback( $example ) // Maybe modify $example in some way return $example;

add_filter( 'example_filter', 'example_callback' );

Since WordPress 1.5.1, bound callbacks can take as many arguments as are passed as parameters in the corresponding apply_filters() call. The $accepted_args parameter allows for calling functions only when the number of args match.

Note: the function will return true whether or not the callback is valid. It is up to you to take care. This is done for optimization purposes, so everything is as quick as possible.


add_filter( $tag, $function_to_add, $priority = 10, $accepted_args = 1 )
 (string) The name of the filter to hook the $function_to_add callback to.
 (callback) The callback to be run when the filter is applied.
 (int) Optional. Used to specify the order in which the functions associated with a particular action are executed. Default 10. Lower numbers correspond with earlier execution, and functions with the same priority are executed in the order in which they were added to the action.
Default: 10
 (int) Optional. The number of arguments the function accepts. Default 1.
Default: 1


(boolean) true


function add_filter( $tag, $function_to_add, $priority = 10, $accepted_args = 1 ) {
	global $wp_filter, $merged_filters;

	$idx = _wp_filter_build_unique_id($tag, $function_to_add, $priority);
	$wp_filter[$tag][$priority][$idx] = array('function' => $function_to_add, 'accepted_args' => $accepted_args);
	unset( $merged_filters[ $tag ] );
	return true;
WP Trac GitHub

Link here