WordPress Hooks, Actions and Filters

Browse manual On this page × Wordpress Manual WordPress Fundamentals Toggle WordPress Fundamentals section What Is WordPress? WordPress.org vs WordPress.com What Can You Build with WordPress? How WordPress Works WordPress Core, Themes, Plugins and Content Essential WordPress Terminology How to Plan a WordPress Website Domains, Hosting, DNS and HTTPS Explained How to Choose WordPress Hosting…

3 min read

  • Article
  • Intermediate
  • 3 minutes read
  • Reviewed August 3, 2026

Hooks are defined points in WordPress execution where code can run or data can be modified.

They allow plugins, themes and WordPress core to cooperate without one component editing another component's files. This extension model is central to WordPress architecture.

The Two Main Hook Types

WordPress uses actions and filters.

An action allows a callback to perform work when a particular event or stage occurs.

A filter passes a value through callbacks and expects each callback to return the value, possibly modified.

Both use the same underlying hook system, but their intent differs.

Actions

An action may run when:

  • WordPress initializes.
  • A post is saved.
  • A user logs in.
  • An administration menu is being registered.
  • Scripts are enqueued.
  • An order or submission is created.

A callback is attached with add_action().

add_action( 'init', 'veyra_register_feature' );

function veyra_register_feature() {
    // Register functionality after WordPress has initialized.
}

The callback performs an operation. It does not need to return a filtered value.

Filters

A filter receives a value and returns a value.

add_filter( 'the_title', 'veyra_prefix_title', 10, 2 );

function veyra_prefix_title( $title, $post_id ) {
    if ( 'event' === get_post_type( $post_id ) ) {
        return 'Event: ' . $title;
    }

    return $title;
}

Every filter callback should return the value, even when no change is made. Failing to return it can break later processing.

Callbacks, Priority and Arguments

When registering a callback, WordPress needs:

  • The hook name.
  • The callback.
  • An optional priority.
  • The number of accepted arguments.

Lower priority numbers generally run earlier. The default priority is 10.

Priority is useful when one extension must run before or after another, but relying on undocumented ordering between third-party plugins can be fragile.

Removing Hooked Callbacks

A callback can be removed only when the same hook, callback identity and priority are known.

This is straightforward for named functions and static methods. Anonymous functions are harder to remove because the original callback instance must be available.

Do not remove another component's behavior casually. Confirm why it exists and whether the integration offers a supported configuration or hook.

Custom Hooks

Plugins can define their own extension points using do_action() and apply_filters().

Well-designed custom hooks allow other developers to extend behavior without forking the plugin.

A custom hook should have:

  • A unique and predictable name.
  • Stable argument order.
  • Documentation.
  • A clear execution point.
  • A compatibility policy when arguments change.

Hooks Do Not Automatically Guarantee Safety

A callback still needs correct capability checks, validation, sanitization, escaping and error handling.

A hook may run in the frontend, administration area, REST request, command-line process or scheduled task. Code should not assume a browser page or logged-in administrator unless the hook guarantees that context.

Hooks and Performance

Frequently executed hooks can accumulate many callbacks.

Avoid expensive database queries or remote requests on broad hooks such as init unless needed. Use narrower hooks, caching and context checks.

Performance problems are often caused not by the hook mechanism itself, but by what callbacks do and how often they run.

Hooks vs Direct Function Calls

Use a direct function or method call when one component explicitly owns the operation and no extension point is required.

Use a hook when other code needs to observe, add to or transform behavior without tight coupling.

Too many undocumented hooks can make execution difficult to follow, while too few hooks force developers to replace or fork code. Good extensibility balances clarity and flexibility.

Frequently Asked Questions

Is an action a type of event?

Conceptually yes. It signals that a stage or event has occurred and allows callbacks to perform work.

Can filters change objects and arrays?

Yes. Filters can pass any value, but callbacks must return the expected type and structure.

Can themes use hooks too?

Yes. Core, plugins and themes all use the WordPress hook system.

Continue Learning

Previous: Shortcodes, Widgets and Blocks

Next: Custom Plugin vs Theme Functions