Codex tools: Log in / create account
Contents |
Hooks a function on to a specific action.
See Plugin API/Action Reference for a list of hooks for action. Actions are (usually) triggered when the Wordpress core calls do_action().
<?php add_action( $tag, $function_to_add, $priority, $accepted_args ); ?>
To email some friends whenever an entry is posted on your blog:
function email_friends($post_ID) {
$friends = 'bob@example.org, susie@example.org';
mail($friends, "sally's blog updated" , 'I just put something on my blog: http://blog.example.com');
return $post_ID;
}
add_action('publish_post', 'email_friends');
The hooked function takes one argument from the action. Specifically, the 'echo_comment_id' function, takes the argument $comment_ID. It then echos the value of the received argument.
function echo_comment_id($comment_ID) {
echo "I just received $comment_ID";
}
add_action('comment_id_not_found','echo_comment_id', 10, 1);
Since: 1.2.0
add_action() is located in wp-includes/plugin.php.
Actions: add_action, do_action, do_action_ref_array, did_action, has_action, remove_action, remove_all_actions