bool add_action ( string $event_name, callable $callback_name, integer $priority = 10, integer $number_of_args = 1 );
Registers your callback to the specified event (action 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.
init. Here is a list of all the available action 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_action 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 Lookup TableBasic
Your callback is registered into the Event Lookup Table when you use
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.
In this video, you will go deeper into the instruction by looking at WordPress Core.
Registering Method or ClosurePro
In this video, you see how to register the following callbacks:
- An object’s method
- Static method
These are the PHP constructs used in WordPress Core for