The What
Syntax
bool add_filter ( string $event_name, callable $callback_name, integer $priority = 10, integer $number_of_args = 1 );
Description
Registers your callback to the specified event (filter hook). When the event fires, the callback is called per the priority specified, and the number of arguments are passed to it. This construct is part of the Plugin API. It allows WordPress, plugins, and themes to be customized, changed, and extended, providing a more rich user experience.
Parameters
event_name
- The name of the event (filter hook) you want to register your callback to, e.g.
the_title
. Here is a list of all the available filter events in WordPress. callback_name
- The fully qualified name of your callback. This is the callback you want to register to this event when it fires.
priority
- optional Specifies the calling order with the lowest number being called first. It allows you to determine when you want your callback to fire. It defaults to 10.
number_of_args
- optional This option indicates how many arguments you want passed to your callback. It defaults to one (1).
Return Values
Returns TRUE
if your callback is successfully registered; else you’ll get a FALSE
back.
Show It in ActionBasic
Let’s see the add_filter
function in action. In this video, you will see how it works.
NamespacingBasic
Let’s talk about namespacing in relationship to registering a callback with add_filter
.
Event Registry Lookup TableBasic
Your callback is registered into the Event Registry Lookup Table when you use add_filter
. Let’s see what this registry looks like and how your callback is stored in it.
Hey... hey you... yes you!... Having a good time? Learning new things? Good!
Calling Too LateBasic
You have to pre-register your callback before the event occurs (fires). In this video, we’ll talk about this and show you what happens.
Registering Method or ClosurePro
In this video, you see how to register the following callbacks:
- An object’s method
- Static method
- Closure
Go DeepPro
In this video, you will go deeper into the instruction by looking at WordPress Core.
PHP Constructs
These are the PHP constructs used in WordPress Core for add_action
: