Step-by-step Guide on How to Remove WooCommerce Breadcrumbs in WordPress

Home » Snippets » Step-by-step Guide on How to Remove WooCommerce Breadcrumbs in WordPress
0

Created with:

Visibility: 

public

Creator: WPTurbo Team

Customize with WPTurbo AI
X

Add Snippet To Project

New Project
Add To Existing Project

If you operate a WordPress site that utilizes the WooCommerce plugin, you may have noticed that breadcrumbs are automatically included on all of your product pages. While breadcrumbs can be useful for site navigation, not all website owners find them valuable or fitting for their site’s design. Perhaps you’d like to declutter your pages or prefer to use an alternative method for site navigation. Regardless of the reason, if you’re looking to remove WooCommerce breadcrumbs from your site, this article will guide you through the process.

					add_action( 'init', 'wpturbo_remove_breadcrumbs' );
function wpturbo_remove_breadcrumbs() {
    remove_action( 'woocommerce_before_main_content', 'woocommerce_breadcrumb', 20, 0 );
}
				

The given code serves to remove the WooCommerce breadcrumbs from your website, which are the trail of links usually found at the top of your product pages.

Firstly, we hook the wpturbo_remove_breadcrumbs() function to the ‘init’ action in WordPress using add_action(). add_action() is a core WordPress function that assigns a custom function to a specific action hook. In this case, the hook is ‘init’, which is executed after WordPress has finished loading but before any headers are sent. It is often used for tasks that need to be set up each time a page is loaded.

add_action( 'init', 'wpturbo_remove_breadcrumbs' );

Within our wpturbo_remove_breadcrumbs() function, we remove the hook for the WooCommerce breadcrumbs. This action would previously display the breadcumbs before the main content, hence its hook – ‘woocommerce_before_main_content’.

function wpturbo_remove_breadcrumbs() {
    remove_action( 'woocommerce_before_main_content', 'woocommerce_breadcrumb', 20, 0 );
}

We use the remove_action() function to unset a previously registered action hook. To remove it, you need to know three parameters that were used to attach the function to the action hook initially. The hook name ‘woocommerce_before_main_content’, the callback function ‘woocommerce_breadcrumb’, and the priority ’20’.

remove_action( 'woocommerce_before_main_content', 'woocommerce_breadcrumb', 20 );

Once the remove_action() is called and the action hook is removed, the WordPress engine will no longer execute the woocommerce_breadcrumb function at the ‘woocommerce_before_main_content’ hook which means that the breadcrumbs will no longer be displayed in your WooCommerce pages. It’s important to note that this change is theme-independent, which means that even if you change your theme, the breadcrumbs will remain hidden unless this code is removed or deactivated.

Register an account to save your snippets or go Pro to get more features.