WordPress.org

Codex

Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/remove action

Description

This function is an alias to remove_filter().

This function removes a function attached to a specified action hook. This method can be used to remove default functions attached to a specific action hook and possibly replace them with a substitute. See also remove_filter(), add_action() and add_filter().

Important: To remove a hook, the $function_to_remove and $priority arguments must match when the hook was added. This goes for both filters and actions. No warning will be given on removal failure.

Usage

<?php remove_action$tag$function_to_remove$priority ); ?>

Parameters

$tag
(string) (required) The action hook to which the function to be removed is hooked.
Default: None
$function_to_remove
(callable) (required) The name of the function which should be removed.
Default: None
$priority
(int) (optional) The priority of the function (as defined when the function was originally hooked).
Default: 10

Return

(boolean
Whether the function is removed.
  • True - The function was successfully removed.
  • False - The function could not be removed.

Example

This function is identical to the remove_filter() function.

 <?php remove_action$tag$function_to_remove$priority ); ?> 

remove_action() must be called inside a function and cannot be called directly in your plugin or theme.

add_action( 'wp_head', 'remove_my_action' );
function remove_my_action(){
	remove_action( 'wp_footer', 'function_being_removed' );
}

If an action has been added from within a class, for example by a plugin, removing it will require accessing the class through a variable that holds the class instance. Unless the function is static in which case you could call the class and function directly.

add_action( 'wp_head', 'remove_my_class_action' );
function remove_my_class_action(){
	global $my_class;
	remove_action( 'wp_footer', array( $my_class, 'class_function_being_removed' ) );
}

Unless the function is static in which case you could call the class and function directly.

add_action( 'wp_head', 'remove_my_class_action' );
function remove_my_class_action(){
	remove_action( 'wp_footer', array( 'My_Class', 'class_function_being_removed' ) );
}

Notes

  1. You may need to prioritize the removal of the action to a hook that occurs after the action is added.
  2. You cannot successfully remove the action before it has been added.
  3. You also cannot remove an action after it has been run.
  4. To remove an action the priority must match the priority with with the function was originally added.

Notes

Change Log

Since: 1.2.0

Source File

remove_action() is located in wp-includes/plugin.php.

Related

Actions: has_action(), add_action(), do_action(), do_action_ref_array(), did_action(), remove_action(), remove_all_actions()

External Resources

See also index of Function Reference and index of Template Tags.