cancel
Showing results for 
Search instead for 
Did you mean: 

Breadcrumbs in Magento 2

Breadcrumbs in Magento 2

Hi,

 

In our website, some products view page has proper breadcrumbs with Home -> Product Category -> Product Name

 

But some products don't have a proper breadcrumb. Home  -> Product Name

 

But all products are added in the same way only. 

 

How to solve this issues?

 

Thanks.

6 REPLIES 6

Re: Breadcrumbs in Magento 2

When you land on product page from category page then breadcrumb will be

 

Home -> Product Category -> Product Name

 

But when you click on product other then category listing page then breadcrumb will be 

 

Home  -> Product Name

 

This is not a issue that how magento work.

Find helpful ? Consider Giving Kudos to this post.
Problem solved? Click Accept as Solution!"
Qaisar Satti

Re: Breadcrumbs in Magento 2

Hi @jeganee

 

Well there should be a two reason behind this !

 

First is As @qaisar_satti said - yes its correct - its default flow of magento for Breadcrumbs , that's correct and that will work like same !

 

Second is there might a chance where your few products are not assigned to any categories or its directly under the root (default) category on that time as well full path not shown on the breadcrumb 

 

so its native behavior of magento !

 

Hope it helps !

 

 

if issue solved,Click Kudos & Accept as Solution

Re: Breadcrumbs in Magento 2

Hi @jeganee
I agree with this and its default magento flow  but if you still want show cateory name into breadcrumbs then you need to customize or use paid extension.  Kindly find below extension link and it's work for me.
https://www.magestyapps.com/magento-2-extensions/advanced-breadcrumbs-m2.html


public_html/app/design/frontend/default/YOUR-TEMPLATE/template/page/html/ breadcrumbs.phtml

public function getCrumbs()
{
    $evercrumbs = array();

    $evercrumbs[] = array(
        'label' => 'Home',
        'title' => 'Go to Home Page',
        'link' => $this->_storeManager->getStore()->getBaseUrl(),
        'key' => 'home'
    );

    $path = $this->_catalogData->getBreadcrumbPath();
    $product = $this->registry->registry('current_product');
    $categoryCollection = clone $product->getCategoryCollection();
    $categoryCollection->clear();
    $categoryCollection->addAttributeToSort('level', $categoryCollection::SORT_ORDER_DESC)->addAttributeToFilter('path', array('like' => "1/" . $this->_storeManager->getStore()->getRootCategoryId() . "/%"));
    $categoryCollection->setPageSize(1);
    $breadcrumbCategories = $categoryCollection->getFirstItem()->getParentCategories();
    foreach ($breadcrumbCategories as $category) {
        $evercrumbs[] = array(
            'label' => $category->getName(),
            'title' => $category->getName(),
            'link' => $category->getUrl(),
            'key' => $category->getUrlKey()
        );
    }


    $evercrumbs[] = array(
            'label' => $product->getName(),
            'title' => $product->getName(),
            'link' => '',
            'key' => $product->getUrlKey()
        );

    return $evercrumbs;
}

Problem solved? Click Accept as Solution!"

Re: Breadcrumbs in Magento 2

Hi,

Yes!. Right

 

When you land on the product page from category page then breadcrumb will be

 

Home -> Product Category -> Product Name

 

Sometimes it's working properly. But sometimes same product not working properly.

Confused. Yesterday I checked some list of products its working fine, the same product I checked today that corresponding breadcrumbs not working properly.

 

In one category, some products have proper breadcrumbs and some products don't have proper breadcrumbs.

 

Don't know how to solve this issue? How to come this issue?

 

Thanks

Re: Breadcrumbs in Magento 2

Hi,

 

I checked the file. In my project, I have 3 breadcrumbs.phtml files. But all are looks like HTML files only. Don't have functions and also I search getCrumbs() into whole project files can't able to find it out.

 

Please give a detailed solution to check that file.

 

Thanks.

Re: Breadcrumbs in Magento 2

Hi,

Yes!. Right

 

When you land on the product page from category page then breadcrumb will be

 

Home -> Product Category -> Product Name

 

Sometimes it's working properly. But sometimes same product not working properly.

Confused. Yesterday I checked some list of products its working fine, the same product I checked today that corresponding breadcrumbs not working properly.

 

In one category, some products have proper breadcrumbs and some products don't have proper breadcrumbs.

 

Don't know how to solve this issue? How to come this issue?

 

Thanks