I have a product called "Wiper blades 60/50cm" which is listed in the store Category "BMW 3 Series e46" I want to add the Category name to the product meta title so that the meta title becomes "Wiper blades 60/50cm BMW 3 Series e46".

I know how to add the Category name to the product name on the frontend page. I don't know how to do it in the meta title. I also know how to add a custom attribute to the meta title. I do it like this in my custom extension:

namespace Tnt\MakeModelInMeta\Observer\Frontend\Catalog;

class ProductLoadAfter implements \Magento\Framework\Event\ObserverInterface {

    * @var \Psr\Log\LoggerInterface
    private $logger;

    public function __construct(
    \Psr\Log\LoggerInterface $logger
    ) {

        $this->logger = $logger;
     * Execute observer
     * @param \Magento\Framework\Event\Observer $observer
     * @return void
    public function execute(
        \Magento\Framework\Event\Observer $observer
    ) {
        $product = $observer->getEvent()->getProduct();
        $category = $observer->getEvent()->getCategory();
        if ($product instanceof \Magento\Catalog\Model\Product) {
            $pageMainTitle = $product->getData('name');
            $newMetaTitle = $pageMainTitle .$product->getData('make_model');

Please help me add the category name in the way that the attribute "make_model" was added in the meta title.

1 Answer 1


Hi you could put in after on the "layout_generate_blocks_after" event and use Magento\Framework\View\Asset\GroupedCollection. Inside you will find several functions for manipulation. I hope this was useful

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.