In WordPress, remove_action()takes a function off an action hook. It undoes a previous add_action(), so the function no longer runs.
You can use it to turn off something that WordPress core, your parent theme, or a plugin added. To remove a function, you must give the same hook name, the same callback, and the same priority that were used to add it.
The first call uses the default 10, so nothing matches and it returns false.
The second call uses 20, so the function is removed and it returns true.
Example 3 — Remove a class method
For a method inside a class, pass the same object and method name in an array.
WordPress
class CTF_Banner {
public function __construct() {
add_action( 'wp_footer', array( $this, 'show_banner' ) );
}
public function show_banner() {
echo '<div class="banner">Sale today!</div>';
}
}
$ctf_banner = new CTF_Banner();
$removed = remove_action( 'wp_footer', array( $ctf_banner, 'show_banner' ) );
echo $removed ? 'Removed: true' : 'Removed: false';
Output
Removed: true
How It Works
The class adds show_banner with array( $this, 'show_banner' ).
remove_action() needs the same object and method name, so we use $ctf_banner.
If you do not have access to the object, you cannot remove the method this way.
Frequently Asked Questions
It removes a function that was added to an action hook with add_action(), so it no longer runs.
Nothing matched. The most common reasons are a different priority, a different callback, or the function was not added yet.
Call it after the function was added. For plugin code, use a later hook such as init or after_setup_theme. For core code, functions.php is usually fine.
It is very hard, because you need the same closure object. Use named functions when you may want to remove them later.
They work the same way. remove_action() is for action hooks and remove_filter() is for filter hooks.