Hook
Quick Definition
A hook is a specific point in WordPress code where you can add your own functionality or modify existing behavior. There are two types: actions (do something) and filters (change something).
What Is a Hook?
According to the official WordPress Plugin Handbook, hooks are "a way for one piece of code to interact/modify another piece of code at specific, pre-defined spots." They are the foundation of WordPress's extensibility — the reason you can install plugins that add features without editing WordPress core files.
WordPress has two types of hooks:
- Actions — "take the info they receive, do something with it, and return nothing." They let you add functionality at a specific point. Example:
wp_headlets plugins inject scripts into the<head>section. - Filters — "take the info they receive, modify it, and return it." They let you change data before it's used. Example:
the_contentlets plugins modify post content before it's displayed.
The key difference: actions do something, filters change something.
Hooks in Practice
Developers interact with hooks using four core functions:
add_action()— attach your function to an action hookadd_filter()— attach your function to a filter hookdo_action()— create/trigger an action hookapply_filters()— create/trigger a filter hook
A real example — adding Google Analytics to every page:
add_action('wp_head', 'my_analytics_code');
function my_analytics_code() {
echo '<script>...GA tracking code...</script>';
}
This tells WordPress: "When you reach the wp_head hook (inside the HTML head section), run my function that outputs the analytics script."
Common WordPress hooks you'll encounter:
wp_head— inject code into<head>(scripts, styles, meta tags)wp_footer— inject code before</body>init— runs after WordPress loads, before outputthe_content— filter that modifies post contentthe_title— filter that modifies post titlessave_post— action that runs when a post is saved
Each callback runs in order of priority (default: 10). Lower numbers run first.
Why It Matters
Hooks are why WordPress has 61,000+ plugins. Every plugin uses hooks to add its features without modifying core code. If you ever use a code snippet plugin like WPCode, you're using hooks. Understanding actions and filters — even at a basic level — helps you customize your site more effectively. See our plugins guide and code snippet plugins for practical applications.