WordPress Hooks

Hooks are used by plugins and themes to “hook” their own functions into WordPress core.  These hooks execute at known times during the running of the site giving your plugin or theme the opportunity to execute its own functions when certain events occur.  These hooks are how a plugin works with WordPress to extend it functionality or change its behavior.

WordPress hooks are split into two types, filter hooks and action hooks.  Action functions are defined in your plugin or theme and are hooked into an action hook. During the execution of WordPress action hooks are executed and the functions hooked to them are called.  An example of an event where an action hook executes is when a post is published.  Hooking your function into the ‘publish_post’ action hook will cause your plugins function to execute every time a post is published.

A full list of the ‘hooks’ are searchable here.

A plugin uses the ‘add_action’ function,

to hook its function to any of the listed WordPress action hooks.  For instance, the ‘activated_plugin’ hook executes when the plugin is activated. By hooking your function into this action you can have your code execute when the plugin is activated.

Actions often do one of the following:

  • Modify database data
  • Send an email message
  • Modify the generated administration screen or front-end page sent to a user browser.

Filter hooks are explained here.

~ Layer7web

Leave a Reply