Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save Nikschavan/f625ae2afa770b04c940de932a8becbc to your computer and use it in GitHub Desktop.
Save Nikschavan/f625ae2afa770b04c940de932a8becbc to your computer and use it in GitHub Desktop.
Remove Untitled category from the breadcrumb.
<?php // don't copy this line in your code.
/**
* Remove uncategorized from the WooCommerce breadcrumb.
*
* @param Array $crumbs Breadcrumb crumbs for WooCommerce breadcrumb.
* @return Array WooCommerce Breadcrumb crumbs with default category removed.
*/
function your_prefix_wc_remove_uncategorized_from_breadcrumb( $crumbs ) {
$category = get_option( 'default_product_cat' );
$caregory_link = get_category_link( $category );
foreach ( $crumbs as $key => $crumb ) {
if ( in_array( $caregory_link, $crumb ) ) {
unset( $crumbs[ $key ] );
}
}
return array_values( $crumbs );
}
add_filter( 'woocommerce_get_breadcrumb', 'your_prefix_wc_remove_uncategorized_from_breadcrumb' );
@pilotmoon
Copy link

It helped me! Thanks.

@Anixed
Copy link

Anixed commented Feb 18, 2020

Thanks! just what I needed.

@eartisan-uk
Copy link

Thanks!

@richjjones
Copy link

Hi... how can I remove all categories from breadcrumb? I still want to be able to categorise my products for grouping and 'related products' but wish to remove any categories from the breadcrumb trail. Many thanks

@qwertyrabin123awale
Copy link

thanks it worked for me.....

@GeorgeFR21
Copy link

It works great! thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment