Popular Action Hooks use in WordPress

In this article we discus about some of the more common Action hooks these are following:

  •  publish_post — It will triggered when a new post is published.
  •  create_category — It will triggered when a new category is created.
  •  switch_theme — It will triggered when you switch themes.
  •  admin_head — It will triggered in the <head> section of the admin dashboard.
  •  wp_head — It will triggered in the <head> section of your theme.
  •  wp_footer — It will triggered in the footer section of your theme usually directly before the </body> tag.
  •  init — It will triggered after WordPress has finished the loading any page or post, but before any headers are sent. The batter place to intercept $_POST and $_GET HTML requests.
  •  admin_init: It is same as init the difference it only runs on admin dashboard pages.
  •  user_register: It triggered when a new user is created.
  •  comment_post: It triggered when a new comment is created.

The most commonly used Action hooks is the wp_head hook. Into the <head> section of WordPress theme you can insert any custom code by using the wp_head hook. Let’s see an example:

<?php
add_action( ‘wp_head’, ‘new_custom_css’ );
function new_custom_css() {  ?>
<style type=”text/css”>
a {          font-size: 14px;
color: #000000;
text-decoration: none;
}
a:hover { font-size: 14px
color: #FF0000;
text-decoration: underline;
}
</style>
<?php } ?>

So the above example will drop anything inside your new_custom_css() function into the header of the WordPress theme, your custom CSS script in this case. Another very commonly used Action hook is the wp_footer, Like the wp_head. Using this hook wp_footer you can insert any custom code in the footer of the WordPress theme. So this is a great method for inserting the analytic tracking code to your website:

Analytics tracking code use in header. By add_action() function.
Analytics tracking code use in header. By add_action() function.

Did you see in the above example that how you can easily insert your Google Analytics tracking code into the footer of every page on your website. Both Action hooks are very similar the admin_head Action hook and the wp_head hook, the using of both hooks in different places, the admin_head Action hook use in the admin dashboard header, rather wp_head hook use in the theme header. These hook very useful when if your plugin requires custom CSS any other custom header code or on the admin dashboard.

In WordPress the user_register Action hook is executed when a new user is created. These users can be created or generate by the new user or by an admin.  By this hook you can set some default values for a new user or to e-mail your new members welcome them for joining your website. In WordPress the Hooks are likely one of the most under-documented features.
Codex is best resource the find the hook which you want.  For the Filter Reference you can visit here (http://www.codex.wordpress.org/Plugin_API/Filter_Reference) and for the Action Reference visit this url (http://www.codex.wordpress.org/Plugin_API/Action_Reference) this sections helpful in tracking down appropriate hooks.

The Plugin Directory is another highly recommended reference (http://wordpress.org/extend/plugins/) on WordPress.org. The best to figure out your problems you can see how the other developers did or accomplished the same task or work.