Home WordPress Hooks Functions remove_filter() WordPress remove_filter() Function Definition In WordPress, remove_filter() takes a function off a filter hook . It undoes a previous add_filter() , so the value is no longer changed by that function.
A popular use is to turn off a built-in filter, such as wpautop, which adds paragraph tags to post content. The rules are the same as remove_action() : use the same hook name, the same callback, and the same priority that were used to add it.
Syntax Use the same values you used in add_filter().
<?php remove_filter( 'the_content', 'wpautop' ); ?> Call What it does remove_filter( 'the_content', 'wpautop' )Stop WordPress from adding paragraph tags to post content. remove_filter( 'the_title', 'my_title', 15 )Remove a function that was added with priority 15. remove_filter( 'the_content', array( $obj, 'note' ) )Remove a method of a class object.
remove_filter() does nothing if the function is not found, so it is safe to call.
Full declaration remove_filter( string $hook_name, callable|string|array $callback, int $priority = 10 ): bool Parameters Parameter Description $hook_namestring. The filter hook the function is attached to. $callbackcallable. The function to remove. For a class method, use the same array that was used to add it. $priorityint. The priority used when it was added. Default is 10. It must match exactly, or the function stays.
Return Value Return Value Description bool true if the function was found and removed. false if nothing matched.
Important
Match, then remove. The hook name, the callback, and the priority must all be the same as in add_filter(). Core filters usually use the default priority 10, but check the source if removal returns false. Use named functions so you can remove them later.
WordPress Examples Three short examples. Each one shows the code and what it prints or does.
1. Turn off automatic paragraphs 2. Remove your own filter 3. Remove a filter on one page Example 1 — Turn off automatic paragraphs Remove the built-in wpautop filter from the post content.
remove_filter( 'the_content', 'wpautop' ); Before:
<p>Line one.</p>
<p>Line two.</p>
After:
Line one.
Line two. How It Works WordPress core adds wpautop to the_content with the default priority 10. remove_filter() matches it and removes it.Post content is no longer wrapped in paragraph tags automatically. You must write your own HTML. Example 2 — Remove your own filter Add a filter, see the result, remove it, and see the result again.
function ctf_shout_title( $title ) {
return strtoupper( $title );
}
add_filter( 'the_title', 'ctf_shout_title', 15 );
echo apply_filters( 'the_title', 'hello' ) . "\n";
remove_filter( 'the_title', 'ctf_shout_title', 15 );
echo apply_filters( 'the_title', 'hello' ); How It Works The filter was added with priority 15, so it turns the title into upper case. remove_filter() uses the same hook, callback, and priority 15.After removal, the same call returns the original text. Example 3 — Remove a filter on one page Remove a filter only when a condition is true. Do it on a hook that runs before the content is shown.
function ctf_landing_no_autop() {
if ( is_page( 'landing' ) ) {
remove_filter( 'the_content', 'wpautop' );
}
}
add_action( 'template_redirect', 'ctf_landing_no_autop' ); Page "landing": automatic paragraph tags are off.
All other pages: unchanged. How It Works template_redirect runs before WordPress loads the template, so the page is already known.is_page( 'landing' ) checks that we are on the landing page.Only then do we remove wpautop. Other pages keep the default filter. Frequently Asked Questions What does remove_filter() do? It removes a function that was added to a filter hook with add_filter(), so it no longer changes the value.
Why does remove_filter() return false? Nothing matched. The hook name, the callback, or the priority is different, or the filter was not added yet.
How do I stop WordPress from adding paragraph tags? Use remove_filter( 'the_content', 'wpautop' ). You can also remove it for excerpts with remove_filter( 'the_excerpt', 'wpautop' ).
Can I remove a filter only on some pages? Yes. Call remove_filter() inside a function hooked to template_redirect or wp, and check the page with a conditional tag.
What is the difference between remove_filter() and remove_action()? They work the same way. remove_filter() is for filter hooks and remove_action() is for action hooks.
Back to the Function Index See all six hooks functions in one table and pick what to learn next.
Hooks Functions Index → About the author Developer, cloud engineer, and technical writer
I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.
12 people found this page helpful
Helpful Share Copy link Suggestion