add_action

Hooks a function on to a specific action.

Description

add_action( (string) $tag, (callable) $function_to_add, (int) $priority = 10, (int) $accepted_args = 1 ); 

Actions are the hooks that the WordPress core launches at specific points during execution, or when specific events occur. Plugins can specify that one or more of its PHP functions are executed at these points, using the Action API.

Parameters (4)

0. $tag (string)
The name of the action to which the $function_to_add is hooked.
1. $function_to_add (callable)
The name of the function you wish to be called.
2. $priority — Optional. (int) => 10
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.
3. $accepted_args — Optional. (int) => 1
The number of arguments the function accepts. Default 1.

Usage

  1. if ( !function_exists( 'add_action' ) ) { 
  2. require_once ABSPATH . WPINC . '/plugin.php'; 
  3.  
  4. // The name of the action to which the $function_to_add is hooked. 
  5. $tag = ''; 
  6.  
  7. // The name of the function you wish to be called. 
  8. $function_to_add = null; 
  9. $priority = 10; 
  10.  
  11. // Optional. The number of arguments the function accepts. Default 1. 
  12. $accepted_args = 1; 
  13.  
  14. // NOTICE! Understand what this does before running. 
  15. $result = add_action($tag, $function_to_add, $priority, $accepted_args); 
  16.  

Defined (2)

The function is defined in the following location(s).

/wp-includes/plugin.php  
  1. function add_action($tag, $function_to_add, $priority = 10, $accepted_args = 1) { 
  2. return add_filter($tag, $function_to_add, $priority, $accepted_args); 
/wp-admin/includes/noop.php  
  1. function add_action() {}