Actions

You've seen a number of add_action() functions called when adding things to wp_head() or admin_head() in themes and plugins. Each add_action() function required two arguments: the name of the action hook and the name of your custom function.

Action hooks are like empty paper cups in the giant Rube Goldberg machine that is WordPress. Imagine a gumball being dropped into the top of your page. This is your page request, and it's going to pass through a number of gizmos before it reaches the bottom. Some of those gizmos include paper cups that will tip over when the gumball falls into them. Adding your own functions to action hooks is like dropping pennies into those paper cups before you let the gumball go. Not only will the gumball fall out and continue on its path when the cup tips over, but your pennies will, too. Notable actions include:

• Init: one of the first things done on every page, both front end and administration

• admin_init: the first thing done on every administration page

• wp_head: the last thing done in the theme <head> section

• admin_head: the last thing done in the administration page's <head> section

• admin_head-$filename: the same, but for a specific administration page

• admin_menu: constructing the navigation menu in the administration pages

• template_redirect: occurs just before the theme template file is chosen, allowing you to override that choice

• wp_enqueue_scripts: printing the list of scripts in the theme header

• wp_print_styles: printing the list of stylesheets in the theme header

• widgets_init: constructing the list of active widgets

• loop_start and loop_end: surrounding the Loop

• wp_footer: the last thing done before the theme's closing </body> tag

Was this article helpful?

0 0

Post a comment