1

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 I remove the Home link completely?

enter image description here

0

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();
    }


}
  • Hi, yes, I mean I've removed that block. However, Home still shows up, but at the end of the list instead. The effect of removing that block is changing Home > Catalog > Product into Catalog > Product > Home. Which is not what I want. Any ideas? – user3591139 Apr 17 '17 at 5:10
-1

I would edit your breadcrumbs.phtml to include an if statement within the foreach loop to check whether the breadcrumb label is not equal to home to then loop through the breadcrumbs.

Something like:

<?php foreach ($crumbs as $crumbName => $crumbInfo) :

if ($block->escapeHtml($crumbInfo['label']) != "Home") {
    //li for breadcrumb here
}

endforeach;
?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.