, ,


After your function is defined, the next step is to “hook” or register it with WordPress. To do this, call add_action() in the global execution space of your plugin file:

add_action ( 'hook_name', 'your_function_name', [priority], [accepted_args] );




  • The name of an action hook provided by WordPress, that tells what event your function should be associated with.


  • The name of the function that you want to be executed following the event specified by hook_name. This can be a standard php function, a function present in the WordPress core, or a function defined by you in the plugin file (such as ’email_friends’ defined above).


  • An optional integer argument 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 added to the action.


  • An optional integer argument defining how many arguments your function can accept (default 1), useful because some hooks can pass more than one argument to your function. This parameter is new in release 1.5.1.

Return Value

  • The (optionally modified) value of the first argument passed to the filter function.

In the example above, we would put the following line in the plugin file:

add_action ( 'publish_post', 'email_friends' );

Likewise, you can also Remove Actions from action hooks. See that section for details.

wordpress badges