What is a Hook in WordPress?
A WordPress hook is a pre-defined spot in WordPress code where you can attach your own function to change how the CMS behaves or add features without editing core files. You register a callback function to a hook, and WordPress runs your code at that point. Hooks come in two types: actions and filters.
More About Hooks
There are two types of hooks in WordPress: actions and filters. Using either one means writing a “callback” function, the code you want to run, and registering it with add_action() or add_filter().
Why hooks exist
Hooks exist so you never have to edit WordPress core files. Core edits don't last: a WordPress update replaces those files, and your changes vanish with it. Code attached to a hook survives every update. The WordPress Plugin Handbook calls hooks the foundation of how plugins and themes interact with WordPress core, and core itself uses them extensively.
Actions vs. filters
The two hook types split the work like this:

- Action hooks run your code when something happens at a specific point, such as WordPress finishing its load sequence (
init) or a post being saved (save_post, which passes the post ID and post object). Use an action to do something: print output, write to the database, send an email. Action callbacks return nothing. - Filter hooks hand your code a piece of data, such as a post title (
the_title) or the CSS classes on the<body>tag (body_class). Use a filter to receive a value, change it, and return it for WordPress to use. Filter callbacks must return a value.
That return is where beginners trip. A filter callback missing its return statement hands nothing back, so the value is lost: a the_title callback without a return blanks every post title on the site. Filter callbacks should also work in isolation and never have side effects, such as changing global variables or printing output. Actions produce effects; filters transform data and hand it back.
Example: filtering a post title
Say you want to change every post title on your site. Write a callback function that takes the title and returns a new version, then register it by passing the hook name and callback name to add_filter( 'the_title', 'wporg_filter_title' );. If the callback returns 'The ' . $title . ' was filtered', a post titled “Learning WordPress” displays as “The Learning WordPress was filtered.” Actions register the same way with add_action().
Both functions accept an optional priority argument that controls when your callback runs relative to others on the same hook. The default priority is 10, typical values run from 1 to 20, and lower numbers run first.
Where to put hook code
Hook code belongs in a child theme's functions.php file or in a plugin, never in WordPress core files. The trade-off: hooks registered in a theme stop running the moment you switch themes, so any behavior your site should keep through a redesign belongs in a plugin. Developers can also define their own custom hooks for other code to attach to.
Frequently Asked Questions
- Yes. Call do_action() where you want an action to fire, or apply_filters() where data should be modifiable, inside your plugin or theme code. Prefix your hook names (like wporg_settings_saved) so they don't collide with hooks from other plugins.
- Call remove_action() or remove_filter() with the same hook name, callback name, and priority used to register it. If the priority doesn't match, removal fails, and WordPress gives no warning. Run your removal code after the original registration, or there's nothing to remove yet.
- No. A WordPress hook runs a PHP callback inside your own site at a pre-defined point in its execution. A webhook is an HTTP request one application sends to another when an event occurs. A hook customizes your site; a webhook connects two separate systems.
Powerful WordPress Hosting
Reliable, lightning-fast hosting solutions specifically optimized for WordPress. Find the perfect plan for you by clicking below.
WordPress Hosting Plans