I am developing a custom theme which never displays the breadcrumb, so I removed it in the default.xml:

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

This caused that the category view page to have empty meta title. Is there a way to programmatically set the meta title for this type of page?


1 Answer 1


Following the suggestion of Alex Constantinescu in his answer I managed to set the category title in the category view page.

Firstly I created a custom block for this purpose:

namespace Custom\Content\Block;

class Title extends \Magento\Framework\View\Element\Template
     * @param \Magento\Framework\Registry $registry
    protected $_registry;

    function __construct(
        \Magento\Framework\View\Element\Template\Context $context,
        array $data = [],
        \Magento\Framework\Registry $registry
        parent::__construct($context, $data);
        $this->_registry = $registry;

    protected function _prepareLayout()
        $category = $this->_registry->registry('current_category');
            $metaTitle = empty($category->getMetaTitle()) ? $category->getName() : $category->getMetaTitle();

In the prepareLayout method I retrieve the current category and set the meta title (if present) or the category name as meta title.

Then I included the block in my catalog_category_view.xml file, without specifying a template:

<referenceBlock name="main">
    <block name="category.title" class="Custom\Content\Block\Title" />

Your Answer

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

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