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/add filter

Description

Hooks a function to a specific filter action.

Filters are the hooks that WordPress launches to modify text of various types before adding it to the database or sending it to the browser screen. Plugins can specify that one or more of its PHP functions is executed to modify specific types of text at these times, using the Filter API. See the Plugin API for a list of filter hooks.

Usage

 <?php add_filter($tag,  $function_to_add,  $priority 10,  $accepted_args 1); ?> 

Parameters

$tag
(string) (required) The name of the filter to hook the $function_to_add to.
Default: None>
$function_to_add
(callback) (required) The name of the function to be called when the filter is applied.
Default: None
$priority
(integer) (option) Used to specify the order in which the functions associated with a particular action are executed. 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
$accepted_args
(integer) (required) The number of arguments the function(s) accept(s). In WordPress 1.5.1 and newer. hooked functions can take extra arguments that are set when the matching do_action() or apply_filters() call is run.
Default: None

Return

true if the $function_to_add is added successfully to filter $tag. How many arguments your function takes. In WordPress 1.5.1+, hooked functions can take extra arguments that are set when the matching do_action() or apply_filters() call is run. For example, the action comment_id_not_found will pass any functions that hook onto it the ID of the requested comment.