Magento – Removing Home from Breadcrumbs

magento2

I need to remove the Home link from the Breadcrumbs (i.e., from Home > Catalog > Product to simply Catalog > Product).

I looked at how to override the _prepareLayout() method of \Magento\Catalog\Block\Breadcrumbs (Change Breadcrumbs Home link's URL 2.1), and that works fine.

However, when I remove the addCrumb method that adds the Home breadcrumb, it removes the Home breadcrumb from the beginning of the list as expected, but the Home breadcrumb gets added again at the end of the list (i.e., Catalog > Product > Home)!

Is there another file appending the Home breadcrumb? How do completely I remove the Home link completely?

enter image description here

Best Answer

As you have follow Change Breadcrumbs Home link's URL 2.1

So, first you need remove

$breadcrumbsBlock->addCrumb(
                'home',
                [
                    'label' => __('Home'),
                    'title' => __('Go to Home Page'),
                    'link' => $this->_storeManager->getStore()->getBaseUrl()
                ]
            );

from rewrite class

add return \Magento\Framework\View\Element\Template::_prepareLayout();

Class:

<?php

namespace [Vendorname]\[Modulename\Plugin;

class Breadcrumbs extends \Magento\Catalog\Block\Breadcrumbs
{
    public function __construct(
            \Magento\Framework\View\Element\Template\Context $context, 
            \Magento\Catalog\Helper\Data $catalogData, 
            array $data = array()) {
           parent::__construct($context, $catalogData, $data);
    }
    protected function _prepareLayout()
    {
        if ($breadcrumbsBlock = $this->getLayout()->getBlock('breadcrumbs')) {


            $title = [];
            $path = $this->_catalogData->getBreadcrumbPath();

            foreach ($path as $name => $breadcrumb) {
                $breadcrumbsBlock->addCrumb($name, $breadcrumb);
                $title[] = $breadcrumb['label'];
            }

            $this->pageConfig->getTitle()->set(join($this->getTitleSeparator(), array_reverse($title)));
        }
        return \Magento\Framework\View\Element\Template::_prepareLayout();
    }


}