Keep On Hacking

How To Remove The Callback From The add_action Hook?

September 27, 2018

WordPress callback function attached to the add_action() hook can be removed using remove_action(). Refer WordPress Codex for details.

<?php
// @see https://developer.wordpress.org/reference/functions/remove_action/
remove_action( string $tag, callable $function_to_remove, int $priority = 10 );

GitHub Gist

Let us look at a real world example. I wanted to remove the Breadcrumb added by WooCommerce in one of the projects in my day job. WooCommerce attaches the woocommerce_breadcrumb() callback to the woocommerce_before_main_content hook.

<?php

/**
 * Breadcrumbs.
 *
 * @see woocommerce_breadcrumb()
 */
add_action( 'woocommerce_before_main_content', 'woocommerce_breadcrumb', 20, 0 );

GitHub Gist

And to remove the callback, all I’ve to do is the following. Remember the $function_to_remove and the $priority must match in order the remove the callback function.

<?php

// To remove a hook, the $function_to_remove and $priority arguments must match with the hook when added.
remove_action( 'woocommerce_before_main_content', 'woocommerce_breadcrumb', 20 );

GitHub Gist


Written by Daniel who lives and works in the beautiful city of Salem training dogs. You should follow me on Twitter

© 2020, Built with ❤️+ Gatsby