WordPress.org

Ready to get started?Download WordPress

Codex

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

Difference between revisions of "Function Reference/add filter"

m (spelling)
(Using Parameter template)
Line 8: Line 8:
   
 
== Parameters ==
 
== Parameters ==
+
{{Parameter|$tag|string|The name of the filter to hook the <tt>$function_to_add</tt> to.}}>
; <tt>$tag</tt> : (''string'') The name of the filter to hook the <tt>$function_to_add</tt> to.
+
{{Parameter|$function_to_add|callback|The name of the function to be called when the filter is [[Function Reference/apply_filters|applied]].}}
+
{{Parameter|$priority|integer|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.|option|10}}
; <tt>$function_to_add</tt> : (''callback'') The name of the function to be called when the filter is applied.
+
{{Parameter|$accepted_args|integer|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.}}
+
; <tt>$priority</tt> : (''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.
 
 
; <tt>$accepted_args</tt> : (''int'') optional. The number of arguments the function accept (default 1). 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.
 
 
 
== Return ==
 
== Return ==
 
<tt>true</tt> if the <tt>$function_to_add</tt> is added successfully to filter <tt>$tag</tt>. How many arguments your function takes. In WordPress 1.5.1+, hooked functions can take extra arguments that are set when the matching <tt>do_action()</tt> or <tt>apply_filters()</tt> call is run. For example, the action <tt>comment_id_not_found</tt> will pass any functions that hook onto it the ID of the requested comment.
 
<tt>true</tt> if the <tt>$function_to_add</tt> is added successfully to filter <tt>$tag</tt>. How many arguments your function takes. In WordPress 1.5.1+, hooked functions can take extra arguments that are set when the matching <tt>do_action()</tt> or <tt>apply_filters()</tt> call is run. For example, the action <tt>comment_id_not_found</tt> will pass any functions that hook onto it the ID of the requested comment.

Revision as of 02:53, 13 January 2008

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.