What Are WordPress Hooks, Actions and Filters?
The Core Distinction
Both actions and filters use the same underlying hook mechanism, but they answer different questions. An action hook (fired with do_action(), listened to with add_action()) says "something happened here, react if you want to" — a new post was published, a user logged in, checkout completed. A filter hook (fired with apply_filters(), listened to with add_filter()) says "here's a piece of data, modify it if you want to" — a post's title before display, an email's subject line, a price before it's shown.
Why This Design Makes WordPress Extensible
- Core WordPress and every plugin/theme fire their own hooks at meaningful points, which is what lets thousands of independently developed plugins all extend the same core software without needing to modify its actual code.
- Multiple pieces of code can hook into the same point, each running in a defined order (controlled by a priority number), which is powerful but also the root cause of most plugin conflicts, since two plugins modifying the same filtered data can produce unexpected combined results.
- A filter must always return a value, even if it does nothing to it — forgetting this is a common beginner mistake that breaks whatever data was being filtered.
- Understanding the specific hooks available for a given task (checked via documentation or a hook-inspection tool) is the actual skill in WordPress development, more so than understanding the general concept itself.
Working With Hooks Effectively
- Use
add_action()when you need code to run at a specific moment without needing to return anything. - Use
add_filter()when you need to modify a piece of data, always returning the (possibly modified) value. - Check for hook priority conflicts if multiple pieces of code are hooking into the same point in unexpected ways.
Need custom hook-based functionality built properly? See WordPress bug fix.