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

enter image description here

1

4 Answers 4

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


}
1
  • 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? Apr 17, 2017 at 5:10
0

Complete code will be something like this.You just need to replace foreach loop section.

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

           if($block->escapeHtml($crumbInfo['label']) != "Home") { ?>

          <li class="item <?php /* @escapeNotVerified */ echo $crumbName ?>">
            <?php if ($crumbInfo['link']) :
                ?>
                <a href="<?php /* @escapeNotVerified */ echo $crumbInfo['link'] ?>" title="<?php echo $block->escapeHtml($crumbInfo['title']) ?>">
                    <?php echo $block->escapeHtml($crumbInfo['label']) ?>
                </a>
            <?php elseif ($crumbInfo['last']) : ?>
                <a href="<?php $crumbInfo['link']; ?>"> <strong><?php echo $block->escapeHtml($crumbInfo['label']) ?></strong></a>
            <?php else: ?>
                <?php   $block->escapeHtml($crumbInfo['label']) ?>
            <?php endif; ?>
            </li>



       <?php       }
               ?>
0

In magento 2.3 You go to this file :

vendor/magento/module-theme/view/frontend/web/js/view/add-home-breadcrumb.js

comment this line 27

    return function (breadcrumb) {

       //breadcrumbList.unshift(homeCrumb());

    return breadcrumb; };
-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.