2

I want to Hide breadcrumbs on specific category page in magento2.

I applied this type of changes:

referenceBlock name="breadcrumbs" remove="false"

But it hide from all the pages.

I need to some specific category page.

Anyone Guide me what types of changes in layout file.

Thanks.

2
  • Do you want to remove for particular category? Then please check my answer which I have verified.
    – P S
    Jan 9, 2018 at 9:14
  • Sorry I had connection problem. Now answer is available and works as per your requirement.
    – P S
    Jan 9, 2018 at 10:37

4 Answers 4

1

Anikesh Sahi@ you can change referenceBlock to referenceContainer and container so working fine

1

Go to admin>Catalog>Categories.

Then goto select your category tree.

Then goto Design tab

And on Layout Update XML field add

<referenceContainer name="breadcrumbs" remove="true/>
0

Please goto admin>Catalog>Categories.

Then goto select your category Categiry tree.

Then goto Design tab

And on Layout Update XML field add

<referenceBlock name="breadcrumbs" remove="true" />

Then flush the cachee

2
  • I also applied layout updated field, but it show error: Please correct the XML data and try again. Element 'referenceBlock': This element is not expected. Expected is one of ( referenceContainer, container, update, move ). Jan 9, 2018 at 8:42
  • let me check....
    – Amit Bera
    Jan 9, 2018 at 8:51
0

If you want to have some control depending upon category id then you cannot use the approach you have shown. It will remove it from all pages. To achieve your target you must override the breadcrumbs.phtml from core file.

1. Create app/code/Vendor/Module/view/frontend/layout/default.xml

<?xml version="1.0"?>
<!--
/**
 * Copyright © 2013-2017 Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<page layout="3columns" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
            <referenceBlock name="breadcrumbs">
                <action method="setTemplate">
                    <argument name="template" xsi:type="string">Vendor_Module::html/breadcrumbs.phtml</argument>
                </action>
            </referenceBlock>
    </body>
</page>

2. Next create app/code/Vendor/Module/view/frontend/templates/html/breadcrumbs.phtml

<?php
/**
 * Copyright © 2013-2017 Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

// @codingStandardsIgnoreFile

?>
<?php
// this code is used to create root category progarmatically.
$canshowBreadcrumbs = true;
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$request = $objectManager->get('\Magento\Framework\App\Request\Http');
if($request->getFullActionName() == 'catalog_category_view')
{

    $registry = $objectManager->get('\Magento\Framework\Registry');
    $restrictedCategoryIds = [3,4];
    $category = $registry->registry('current_category');

    if(in_array($category->getId(), $restrictedCategoryIds)) $canshowBreadcrumbs = false; 
}
?>
<?php if($canshowBreadcrumbs): ?>
    <?php if ($crumbs && is_array($crumbs)) : ?>
    <div class="breadcrumbs">
        <ul class="items">
            <?php foreach ($crumbs as $crumbName => $crumbInfo) : ?>
                <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']) : ?>
                    <strong><?php echo $block->escapeHtml($crumbInfo['label']) ?></strong>
                <?php else: ?>
                    <?php echo $block->escapeHtml($crumbInfo['label']) ?>
                <?php endif; ?>
                </li>
            <?php endforeach; ?>
        </ul>
    </div>
    <?php endif; ?>
<?php endif; ?>
2
  • not require in this type of script which are mentioned above. I found minor changes that is: <referenceContainer name="breadcrumbs" remove="true" /> Jan 9, 2018 at 10:51
  • Using that you will remove The breadcrumbs container, that is right. but your question is different.
    – P S
    Jan 9, 2018 at 10:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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