Remove actions and filters added by core, themes and plugins
Customising WordPress is not only adding callbacks; often you need to remove one: the emoji scripts on a site that does not need them, a parent theme’s output, a plugin’s popup, a WooCommerce email you replaced. remove_action() and remove_filter() do that, but only when three things match exactly: the hook, the callback and the priority, and only after the callback was added.
Problem: A call to remove_action() seems to do nothing: the emoji script, the parent theme’s header output or the plugin’s footer markup is still there.
Solution: Remove the callback with the same hook, the same callable and the same priority it was added with, from a hook that runs after it was added. For object methods you need the same object; closures cannot be removed.
Core: the emoji scripts
Core adds them in wp-includes/default-filters.php, which is loaded before plugins and themes, so removing them directly in a plugin or in functions.php works:
<?php remove_action( 'wp_head', 'print_emoji_detection_script', 7 ); // added with priority 7 remove_action( 'admin_print_scripts', 'print_emoji_detection_script' ); remove_action( 'wp_print_styles', 'print_emoji_styles' ); remove_action( 'admin_print_styles', 'print_emoji_styles' ); remove_filter( 'the_content_feed', 'wp_staticize_emoji' ); remove_filter( 'comment_text_rss', 'wp_staticize_emoji' ); remove_filter( 'wp_mail', 'wp_staticize_emoji_for_email' );
The first line shows the most common mistake: without the 7, WordPress looks for the callback at priority 10 and finds nothing. To see which priority was used, search the source for the add_action() call.
A parent theme
A child theme’s functions.php is loaded before the parent’s, so the parent’s callbacks do not exist yet when it runs. Remove them on a later hook:
<?php
add_action( 'after_setup_theme', function () {
remove_action( 'wp_head', 'parenttheme_custom_header_style', 20 );
}, 20 ); // after the parent's own after_setup_theme callbacks
A plugin class
If a plugin adds array( $this, 'render_popup' ), you need that same object. Well-written plugins make it reachable, for example through a function or a static instance:
<?php
add_action( 'plugins_loaded', function () {
if ( function_exists( 'some_plugin' ) ) {
remove_action( 'wp_footer', array( some_plugin(), 'render_popup' ), 10 );
}
}, 20 );
For static methods the string form works: remove_action( 'init', 'Some_Plugin::register' ).
WooCommerce emails
Emails in WooCommerce are classes, and the cleanest way to disable one is the email’s own setting (WooCommerce → Settings → Emails) or its enabled filter, not removing hooks:
<?php // Never send the "Processing order" email to customers add_filter( 'woocommerce_email_enabled_customer_processing_order', '__return_false' );
When nothing works
A closure (add_action( 'wp_footer', function () { ... } )) cannot be removed with remove_action(), because you cannot pass the same closure object. Hook callbacks are visible in the global $wp_filter; listing them shows what is attached and with which priority, as in hook priorities and execution order. Removing a closure from there is possible but fragile; asking the plugin author for a named callback or a filter is the better fix.
NOTE: remove_action() returns true when something was removed and false otherwise. During development, log the return value: a false means the hook, the callback, the priority or the timing is wrong.