- Article
- Advanced
- 2 minutes read
- Reviewed August 4, 2026
- Advanced WordPress and integrations
Hooks allow themes, plugins and WordPress core to communicate without editing each other's files.
Actions notify code that an event or lifecycle point has occurred. Filters receive a value, allow callbacks to modify it and return the result.
Registering a Callback
A hook registration defines:
- Hook name.
- callback.
- priority.
- accepted argument count.
Lower priority numbers run earlier. Callbacks with the same priority normally run in registration order.
Hook Timing
A callback can run only after it has been registered and when the required data is available.
Examples:
- Register post types on
init. - Configure theme support on
after_setup_theme. - Modify the main query on
pre_get_posts. - Enqueue frontend assets on
wp_enqueue_scripts. - Register REST routes on
rest_api_init. - Add cron schedules through the appropriate filter before scheduling.
Actions and Filters Are Contracts
A public hook becomes part of an extension contract.
Document:
- When it fires.
- Which values are passed.
- Whether values are mutable.
- Expected return type.
- performance constraints.
- security context.
- deprecation strategy.
Prefix or namespace custom hook names to avoid collisions.
Removing Callbacks
To remove a callback, use the same hook, callback identity and priority used during registration.
Anonymous functions are difficult to remove later unless their reference is retained.
Re-Entrancy and Repetition
Some hooks can fire more than once.
Use did_action(), explicit state or idempotent logic when repetition would create duplicate data or side effects.
Hook Performance
Frequently fired hooks can execute many times per request.
Avoid database queries, remote calls and large computations unless the result is genuinely required. Cache or defer expensive work.
Frequently Asked Questions
Is a high priority number more important?
No. It runs later.
Can filters perform side effects?
They can technically, but filters are easier to reason about when they transform and return the supplied value.
Continue Learning
Previous: The WordPress Request Lifecycle