WordPress Hooks

General

Action Hooks

Filter Hooks

Basic Format

We create a function which contains a call to a hook which is then added as an action for WP to execute.

[php]
function example_function() {
// Call hook w/parameters.
}

add_action( $hook_name, $function_name, $priority, $arguments );
[/php]
  • $hook_name is the name of the hook we want to use.
  • $function_name is the name of our custom function.
  • $priority
  • $arguments is the number of arguments used by our custom function.
  • remove_action() and remove_all_actions() can be used to remove actions from a hook.
  • If we want to add functions to our plugin or theme we use do_action() or do_action_ref_array()/
  • Checking to See if a Hook Has Any Actions Associated
[php]
if( has_action( 'some_action' ) {
add_action( 'some_action', 'my_custom_action' );
}
[/php]