Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save cccamuseme/17a78b0593d4f5d1253f5b04ab2c8243 to your computer and use it in GitHub Desktop.
Save cccamuseme/17a78b0593d4f5d1253f5b04ab2c8243 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' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment