bool add_filter ( string $event_name, callable $callback_name, integer $priority = 10, integer $number_of_args = 1 );
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.
- 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.
- The fully qualified name of your callback. This is the callback you want to register to this event when it fires.
- 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.
- optional This option indicates how many arguments you want passed to your callback. It defaults to one (1).
TRUE if your callback is successfully registered; else you’ll get a
Show It in ActionBasic
Let’s see the
add_filter function in action. In this video, you will see how it works.
Let’s talk about namespacing in relationship to registering a callback with
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
In this video, you will go deeper into the instruction by looking at WordPress Core.
These are the PHP constructs used in WordPress Core for