I wanted to add a static text with a link in front of my category page and product page breadcrumbs.

Existing Breadcrumbs

Home > Category > Sub Category > Sub Category

How I want it to be

Home > Static Text with link > Category > Sub Category > Sub Category

Remember, my cms pages breadcrumbs need to remain as they are. Not like above.


You need to make changes in below file. vendor/magento/module-theme/view/frontend/templates/html/breadcrumbs.phtml

 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.

// @codingStandardsIgnoreFile

<?php if ($crumbs && is_array($crumbs)) : ?>
<div class="breadcrumbs">
    <ul class="items">
        <?php foreach ($crumbs as $crumbName => $crumbInfo) : ?>
            <li class="item <?= /* @escapeNotVerified */ $crumbName ?>">
            <?php if ($crumbInfo['link']) : ?>
                <a href="<?= /* @escapeNotVerified */ $crumbInfo['link'] ?>" title="<?= $block->escapeHtml($crumbInfo['title']) ?>"><?= $block->escapeHtml($crumbInfo['label']) ?></a>
            <?php elseif ($crumbInfo['last']) : ?>
                <strong><?= $block->escapeHtml($crumbInfo['label']) ?></strong>
            <?php else: ?>
                <?= $block->escapeHtml($crumbInfo['label']) ?>
            <?php endif; ?>
            //custom code by John
           //your customer code here, 
            if ($crumbName == "home") : ?>
                <li class="item">
                    <a href="Your static link here" title="">Your static link title here</a>
          <?php endif; ?>
        <?php endforeach; ?>
<?php endif; ?>

see above and make necessary changes in same file. Note: it will be preferable if you can override this file. How to override .phtml files in Magento 2 Also, change href link and title on above code. To check if current page is cms page or category page Magento 2.2.2 how to check if current page is a CMS page in .phtml file?

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.