Filter
Quick Definition
A filter is a type of WordPress hook that lets you modify data before it's displayed or saved. Filters receive data, change it, and return it — like modifying a post title or adding a CSS class to the body tag.
What Is a Filter?
A filter is one of the two types of WordPress hooks (the other being actions). According to the official Plugin Handbook, "filters provide a way for functions to modify data during the execution of WordPress Core, plugins, and themes."
The key rule: a filter receives data, modifies it, and returns it. It's like a pipeline — data goes in, gets changed, and comes back out. If your callback function doesn't return the data, you'll break whatever was using that filter.
Filters are different from actions in two important ways:
- Filters must return data — actions return nothing
- Filters should have no side effects — they shouldn't output HTML, modify global variables, or write to the database. They should only modify and return the data they receive.
Filters in Practice
You interact with filters using two functions:
add_filter('hook_name', 'your_function', priority, args)— attach your callback to a filterapply_filters('hook_name', $value)— create a filter hook (for plugin/theme developers)
A simple example — adding " | ZeroToWP" to every page title:
add_filter('the_title', 'append_site_name');
function append_site_name($title) {
return $title . ' | ZeroToWP';
}
Common WordPress filters you'll encounter:
the_content— modify post content before displaythe_title— modify post/page titlesthe_excerpt— modify the excerptbody_class— add CSS classes to the<body>tagwp_mail— modify outgoing emailsupload_mimes— control which file types can be uploadedlogin_redirect— change where users go after logging in
The priority parameter (default: 10) controls execution order. Use remove_filter() to detach a previously added filter.
Why It Matters
Filters are how plugins modify your site without editing core files. Your SEO plugin uses the_title and the_content to add meta tags. Even if you never write a filter yourself, understanding them helps you troubleshoot plugin conflicts. See our plugins guide and code snippet plugins.