Remove the last item from WooCommerce breadcrumbs

To remove the product header in breadcrumbs, rewrite the breadcrumbs template breadcrumb.php

<?php

if ( ! defined( 'ABSPATH' ) ) {
   exit;
}

if ( ! empty( $breadcrumb ) ) {

   echo $wrap_before;

   foreach ( $breadcrumb as $key => $crumb ) {

      echo $before;

      if ( ! empty( $crumb[1] ) && sizeof( $breadcrumb ) !== $key + 1 ) {
         echo '<a href="' . esc_url( $crumb[1] ) . '">' . esc_html( $crumb[0] ) . '</a>';
      } else {
            if(!is_singular()){
                echo esc_html( $crumb[0] );
            }
      }

      echo $after;
        if(sizeof( $breadcrumb ) -2 == $key && (is_singular())){
            continue;
        }

      if ( sizeof( $breadcrumb ) !== $key + 1 ) {
         echo $delimiter;
      }
   }

   echo $wrap_after;

}

In addition, you need to remove the last element of bread crumbs from the micromarking. Add this code to functions.php:

add_filter('woocommerce_structured_data_breadcrumblist', 'remove_last_woocommerce_structured_data_breadcrumblist',10,1);

function remove_last_woocommerce_structured_data_breadcrumblist($markup){
    if(is_singular()){
        array_pop($markup['itemListElement']);
    }
    return $markup;
}

Updated: 18.11.2018

Did this article help you? Rate it!
(No Ratings Yet)
Loading...


Leave a Reply

Your email address will not be published. Required fields are marked *