NO, the full page cache is not the culprit.
DON'T DISABLE FULL PAGE CACHE.
The logic flow is clearly described in \Magento\Catalog\Helper\Data::getBreadcrumbPath()
when it runs $category = $this->getCategory()
.
Just see the getCategory()
code
/**
* Return current category object
*
* @return \Magento\Catalog\Model\Category|null
*/
public function getCategory()
{
return $this->_coreRegistry->registry('current_category');
}
It returns an object saved in the registry called current_category
. If the object is not present, the breadcrumbs will be empty.
For example, if you make a first time access (clean browser and magento cache) to a product directly from search box, you will have that breadcrumbs will be empty because registry('current_category')
was not setted.
Otherwise, if you make a first time access (clean browser and magento cache) to a product after visited its category, breadcrumbs will be present, because registry('current_category')
was setted.
Then, every time you make a second visit to same product page you just see the same result, because FPC (FULL PAGE CACHE) JUST CACHE EVERY GET REQUEST AND RESPONSE WITH THE CONTENT OF THE FIRST TIME VISIT.
Best Answer
Go to Admin > Stores > Configuration > Catalog > Catalog > Search Engine Optimization > Set "Yes" for Use Categories Path for Product URLs option.
You need to reindex after configure this setting and need to flush cache.
Please check and accept the answer if it's helpful.
Now add below code just after body tag in catalog_product_view.xml
Now just override below file into your current theme.
vendor/magento/module-theme/view/frontend/templates/html/breadcrumbs.phtml
Clean cache after that and check again.