Home » Wordpress » How to Remove Shop from BreadCrumb ? I want to Set Bread crumb as my navigation menu

How to Remove Shop from BreadCrumb ? I want to Set Bread crumb as my navigation menu

Posted by: admin November 30, 2017 Leave a comment

Questions:

How to Remove Shop Text from Bread Crumb in woo commerce?[Home–>Shop–>Pink Himalayan Salt] I want to Set Bread crumb as per my Navigation menu in m WordPress site.[Home–>Products–>Salt–>Pink Himalayan Salt] I have used some Pages, Custom Links, Categories & Products to My main Menu.

See screenshot.

Bredcrumb –
enter image description here


Menu –
https://www.screencast.com/t/To2xchRWJo

Answers:

This might be solved with CSS, but cannot help unless you post a link to your shop.
Try like this:

Add this line to your custom CSS

ul.breadcrumbs li:nth-of-type(2) {display:none}

If it does not work, might also need !important

ul.breadcrumbs li:nth-of-type(2) {display:none!important}

I cannot comment that is why I had to answer. please provide the link of your site. I’ll update my answer with exact CSS.

Questions:
Answers:

You can override WooCommerce templates via the theme (read the following official documentation):

Template Structure + Overriding Templates via a Theme

Once you have copied the file from plugins/woocommerce/templates/global/breadcrumb.php
to: themes/yourtheme/woocommerce/global/breadcrumb.php, you will be able to change the code by replacing it with the following:

<?php
/**
 * Shop breadcrumb
 *
 * This template can be overridden by copying it to yourtheme/woocommerce/global/breadcrumb.php.
 *
 * HOWEVER, on occasion WooCommerce will need to update template files and you
 * (the theme developer) will need to copy the new files to your theme to
 * maintain compatibility. We try to do this as little as possible, but it does
 * happen. When this occurs the version of the template file will be bumped and
 * the readme will list any important changes.
 *
 * @see         https://docs.woocommerce.com/document/template-structure/
 * @author      WooThemes
 * @package     WooCommerce/Templates
 * @version     2.3.0
 * @see         woocommerce_breadcrumb()
 */

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

if ( ! empty( $breadcrumb ) ) {

    $breadcrumb0 = $breadcrumb[0];
    $shop_txt = __( 'Shop', 'woocommerce' );
    $products_txt = __( 'Products', 'woocommerce' );
    $products_url = home_url( '/products/' );
    $breadcrumb10 = array( $products_txt );
    $breadcrumb11 = array( $products_txt, $products_url );
    if(is_product() || is_shop() || is_product_category() || is_product_tag() ){
        if( $breadcrumb[1][0] == $shop_txt ){
            if( ! empty( $breadcrumb[1][1] ) )
                $breadcrumb[1] = $breadcrumb11;
            else
                $breadcrumb[1] = $breadcrumb10;
        } else {
            unset($breadcrumb[0]);
            array_unshift($breadcrumb, $breadcrumb0, $breadcrumb11);
        }
    }

    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 {
            echo esc_html( $crumb[0] );
        }

        echo $after;

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

    echo $wrap_after;

}

This will:

  1. Replace “Shop” by “Products”
  2. Add “Products” just after “Home” when “Shop” doesn’t exits.

So your breadcrumps will always start with: Home > Products on shop, archives and single product pages…

Questions:
Answers:

I have Got the answer by doing changes on functions.php
https://www.screencast.com/t/U42lqPduY707

if (get_post_type() ==  'product')
{
echo sprintf($link, '#', esc_html__('Products', 'thegem'));
//echo sprintf($link, get_permalink(get_option ('woocommerce_shop_page_id' , 0 )), esc_html__('Product', 'thegem'));
$taxonomy = 'product_cat';
$terms = get_the_terms( $post->ID, $taxonomy );
foreach ( $terms as $c ) {
$c->term_id;
//  echo '<a href="' . get_term_link($c, 'product_cat') . '">' . ($c->name ) . '</a>';
if($c->term_id=='36') {
echo $delimiter;
echo sprintf($link, get_permalink( 106 ), esc_html__($c->name, 'thegem'));
}
}
}
else {
$slug = $post_type->rewrite;
printf($link, $home_link . '/' . $slug['slug'] . '/', $post_type->labels->singular_name);
}