Categories
PHP Wordpress

Adding actions to wordpress based on events

add_action($tag, $function_to_add, $priority, $accepted_args);
add_filter($tag, $function_to_add, $priority, $accepted_args);

The $tag parameter is where you specify the hook you want to add to; $function_to_add is the name of your function. The next two are optional, but worth knowing about: $priority is used to determine the order in which your action ought to occur, relative to other actions that might be happening on the same hook—larger numbers happen later. $accepted_args

And to remove them (notice you have to do this indirectly):

function remove_some_filter() {
  remove_filter(tag, function, priority, args);
}

add_action('init', 'remove_some_filter')


Example:

add_action('wp_head', 'wicked_favicon')

This runs everytime the page head is constructed, you can have the specific function inside functions.php:

function wicked_favicon() {
  echo '<link rel="shortcut icon" href="' 
      . get_bloginfo('stylesheet_directory') 
      . '/images/favicon.ico"/>';
}

Leave a Reply

Your email address will not be published. Required fields are marked *