Using WordPress ‘remove_action()’ PHP function

The remove_action() WordPress PHP function removes a callback function from an action hook. This can be used to remove default functions attached to a specific action hook and possibly replace them with a substitute.

Usage

remove_action( $hook_name, $callback, $priority );

Parameters

  • $hook_name (string) – The action hook to which the function to be removed is hooked.
  • $callback (callable|string|array) – The name of the function which should be removed.
  • $priority (int) – The exact priority used when adding the original action callback. Default: 10

More information

See WordPress Developer Resources: remove_action()

Examples

Remove a function called function_being_removed from the wp_footer action hook.

add_action( 'wp_head', 'remove_my_action' );

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

Remove a class method called class_function_being_removed from the wp_footer action hook.

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' ) );
}

Remove a static class method called class_function_being_removed from the wp_footer action hook.

add_action( 'wp_head', 'remove_my_class_action' );

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

Remove a function with a specific priority

Remove a function called function_being_removed from the wp_footer action hook with a priority of 20.

add_action( 'wp_head', 'remove_my_action' );

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

Remove a function with an anonymous class method

Remove an anonymous class method from the wp_footer action hook.

add_action( 'wp_head', 'remove_anonymous_class_action' );

function remove_anonymous_class_action() {
    remove_action( 'wp_footer', array( 'My_Anonymous_Class', 'class_function_being_removed' ) );
}