Customize WooCommerce Breadcrumbs

You customize the WooCommerce breadcrumb with two filters: woocommerce_breadcrumb_defaults controls the markup around the trail, and woocommerce_get_breadcrumb controls the crumbs themselves. Below is a reference for both, checked against the WooCommerce source code.

If all you need is a different separator, the shorter guide Change the Breadcrumb Delimiter in WooCommerce covers that case. Add every snippet below to your child theme’s functions.php file.

Every woocommerce_breadcrumb_defaults Argument

The filter receives an array of six keys. These are the default values in woocommerce_breadcrumb() in includes/wc-template-functions.php:

Argument Default What it does
delimiter  /  Printed between crumbs, never after the last one.
wrap_before <nav class="woocommerce-breadcrumb" aria-label="Breadcrumb"> Opening markup before the whole trail.
wrap_after </nav> Closing markup after the whole trail.
before Empty string Printed before each crumb.
after Empty string Printed after each crumb, before the delimiter.
home _x( 'Home', 'breadcrumb', 'woocommerce' ) Label of the first crumb. An empty value removes the Home crumb.

The aria-label on wrap_before was added in WooCommerce 8.3. Older tutorials show <nav class="woocommerce-breadcrumb"> without it.

Change Several Breadcrumb Defaults

This example turns the trail into an ordered list. Edit the keys you need and leave the others alone:

/**
 * Output the WooCommerce breadcrumb as an ordered list.
 */
function savvy_wc_breadcrumb_defaults( $defaults ) {
    $defaults['wrap_before'] = '<nav class="woocommerce-breadcrumb" aria-label="Breadcrumb"><ol>';
    $defaults['wrap_after']  = '</ol></nav>';
    $defaults['before']      = '<li>';
    $defaults['after']       = '</li>';
    $defaults['delimiter']   = '';
    $defaults['home']        = __( 'Store', 'your-textdomain' );
    return $defaults;
}
add_filter( 'woocommerce_breadcrumb_defaults', 'savvy_wc_breadcrumb_defaults', 20 );

With an empty delimiter you can draw separators in CSS, for example with .woocommerce-breadcrumb li + li::before.

How It Works

WooCommerce hooks woocommerce_breadcrumb() to woocommerce_before_main_content at priority 20. The function runs in this order:

  1. Applies woocommerce_breadcrumb_defaults to the default array.
  2. Merges any $args passed directly to woocommerce_breadcrumb( $args ), which override the filtered defaults.
  3. Adds the Home crumb (URL from woocommerce_breadcrumb_home_url) and builds the trail with the WC_Breadcrumb class.
  4. Fires the woocommerce_breadcrumb action, which generates BreadcrumbList schema.
  5. Loads global/breadcrumb.php.

The template echoes wrap_before, wrap_after, before, after and delimiter as raw HTML. Crumb names are escaped, and home passes through wp_strip_all_tags(), so HTML in the Home label is removed.

More Breadcrumb Customizations

These cover the other common requests: the Home link, the crumbs array and removing the trail.

Change the Home Link URL

By default the Home crumb points to home_url(). This sends it to the shop page instead:

function savvy_wc_breadcrumb_home_url( $url ) {
    return wc_get_page_permalink( 'shop' );
}
add_filter( 'woocommerce_breadcrumb_home_url', 'savvy_wc_breadcrumb_home_url' );

Modify the Crumbs with woocommerce_get_breadcrumb

The $crumbs array holds one entry per crumb, each an indexed array of name and URL: array( 'Home', 'https://example.com' ). This removes the product title from single product pages:

function savvy_wc_breadcrumb_crumbs( $crumbs, $breadcrumb ) {
    if ( is_product() && count( $crumbs ) > 1 ) {
        array_pop( $crumbs );
    }
    return $crumbs;
}
add_filter( 'woocommerce_get_breadcrumb', 'savvy_wc_breadcrumb_crumbs', 10, 2 );

The same array feeds the schema, so your changes appear there too. If you unset() a crumb from the middle, wrap the result in array_values() to keep the positions sequential.

Remove the Breadcrumb Completely

This is useful when you add breadcrumbs with an SEO plugin instead:

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

Storefront moves the breadcrumb to storefront_before_content at priority 10, so on Storefront remove it from that hook instead. To hide it only on certain pages, see Remove WooCommerce Breadcrumbs on Specific Pages.

Storefront and Block Themes

Storefront filters woocommerce_breadcrumb_defaults at priority 10 to set its own delimiter, wrap_before and wrap_after. The parent theme loads after your child theme, so use priority 20 or higher to win.

In block themes the Store Breadcrumbs block calls woocommerce_breadcrumb(), so both filters on this page work there as well.

FAQs

Common questions about customizing WooCommerce breadcrumbs:

What is the difference between before/after and wrap_before/wrap_after?
wrap_before and wrap_after are printed once, around the whole trail. before and after are printed around every single crumb, which is how you output list items.
How do I remove the Home crumb?
Set $defaults['home'] to an empty string in the woocommerce_breadcrumb_defaults filter. WooCommerce only adds the Home crumb when that value is not empty.
Is there a WC()->breadcrumb property?
No. To get the crumbs in your own code, create new WC_Breadcrumb() and call its generate() method. That array has no Home crumb, since woocommerce_breadcrumb() adds it before generating.
Can I override the breadcrumb template instead?
Yes. Copy templates/global/breadcrumb.php to yourtheme/woocommerce/global/breadcrumb.php. Use the filters when you can, since overridden templates need updating when WooCommerce changes them.
Discussion
[  0 Comments  ]

Leave a Comment

To add code, use the buttons below. For instance, click the PHP button to insert PHP code within the shortcode. If you notice any typos, please let us know!