ZeroToWP

Action

Quick Definition

An action is a type of WordPress hook that lets you run custom code at a specific point during execution. Unlike filters, actions do something but don't return data — like sending an email when a post is published.

WordPress plugins use actions to add functionality at specific execution points

What Is an Action?

An action is one of the two types of WordPress hooks (the other being filters). According to the Plugin Handbook, "actions provide a way for running a function at a specific point in the execution of WordPress Core, plugins, and themes."

The key distinction from filters: action callbacks do not return anything. They execute code — send an email, write to the database, output HTML, log an event — and then exit. They act on something rather than modifying something.

Think of it this way:

  • Actions = "When X happens, also do Y"
  • Filters = "Before X is used, change it to Z"

Actions in Practice

You register actions with add_action():

add_action('hook_name', 'your_function', priority, args);

Parameters:

  • hook_name (required) — which action to hook into
  • callback (required) — your function to run
  • priority (optional, default: 10) — execution order (lower = earlier)
  • accepted_args (optional, default: 1) — how many parameters your function receives

Example — sending a notification when a post is published:

add_action('publish_post', 'notify_admin');
function notify_admin($post_id) {
    wp_mail('admin@example.com', 'New Post', 'A new post was published.');
}

Common WordPress actions:

  • init — fires after WordPress loads, before any output
  • wp_head — fires inside <head>
  • wp_footer — fires before </body>
  • wp_enqueue_scripts — the proper way to load CSS and JavaScript
  • save_post — fires when a post is saved
  • admin_init — fires on every admin page load

Use do_action() to create your own actions, and remove_action() to detach a callback.

Why It Matters

Actions are the backbone of WordPress's event-driven architecture. Every plugin that adds a feature does it through actions. See our plugins guide and code snippet plugins.

Related Terms

Related Articles