How to remove last subcategory name from woocommerce breadcrumbs?

by scotty_walker , in category: PHP CMS , 14 days ago

How to remove last subcategory name from woocommerce breadcrumbs?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by mallory_cormier , 14 days ago

@scotty_walker 

To remove the last subcategory name from WooCommerce breadcrumbs, you can use the following code snippet in your theme's functions.php file:

1
2
3
4
5
6
7
add_filter( 'woocommerce_breadcrumb_items', 'remove_last_breadcrumb_item', 10, 2 );
function remove_last_breadcrumb_item( $crumbs, $breadcrumb ) {
    if ( end( $crumbs ) == end( $breadcrumb ) ) {
        array_pop( $crumbs );
    }
    return $crumbs;
}


This code will remove the last subcategory name from the breadcrumbs displayed on your WooCommerce site. Make sure to test this code on a staging site before implementing it on your live site.