In app/design/frontend/VendorTheme/ThemeName/Magento_Catalog/layout/catalog_product_view.xml
<?xml version="1.0"?>
<page>
<body>
<referenceBlock name="breadcrumbs" remove="true" />
<referenceContainer name="page.top">
<block class="XXX\Breadcrumbs\Block\Breadcrumbs" name="product.view.breadcrumbs" template="Magento_Theme::html/breadcrumbs.phtml" />
</referenceContainer>
</body>
</page>
In app/design/frontend/VendorTheme/ThemeName/Magento_Theme/templates/html/breadcrumbs.phtml:
<?php $crumbs = $block->getBreadcrumb(); ?>
<?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 else: ?>
<?= $block->escapeHtml($crumbInfo['label']) ?>
<?php endif; ?>
</li>
<?php endforeach; ?>
</ul>
</div>
<?php endif; ?>
In App/Code/XXX/Breadcrumbs/Block/Breadcrumbs.php:
<?php
namespace XXX\Breadcrumbs\Block;
use Magento\Catalog\Helper\Data;
use Magento\Framework\View\Element\Template\Context;
class Breadcrumbs extends \Magento\Theme\Block\Html\Breadcrumbs
{
/**
* Catalog data
*
* @var Data
*/
protected $_catalogData = null;
protected $path = array();
/**
* @param Context $context
* @param Data $catalogData
* @param array $data
*/
public function __construct(Context $context, Data $catalogData, array $data = [])
{
$this->_catalogData = $catalogData;
parent::__construct($context, $data);
}
public function getTitleSeparator($store = null)
{
$separator = (string) $this->_scopeConfig->getValue('catalog/seo/title_separator', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $store);
return ' ' . $separator . ' ';
}
public function getBreadcrumb()
{
$this->addCrumb(
'home', [
'label' => __('Home'),
'title' => __('Go to Home Page'),
'link' => $this->getBaseUrl()
]
);
foreach ((array) $this->path as $name => $breadcrumb) {
$this->addCrumb($name, $breadcrumb);
}
return $this->getCrumbs();
}
protected function _prepareLayout()
{
$this->path = $this->_catalogData->getBreadcrumbPath();
$title = [];
foreach ((array) $this->path as $name => $breadcrumb) {
$title[] = $breadcrumb['label'];
}
return $this->pageConfig->getTitle()->set(join($this->getTitleSeparator(), array_reverse($title)));
//return parent::_prepareLayout();
}
public function getCrumbs()
{
return $this->_crumbs;
}
public function getBaseUrl()
{
return $this->_storeManager->getStore()->getBaseUrl();
}
}
If you got it, let me know.