I want to Change my header title tag product wise dynamically.my Magento version is 2.3.4. how can I get SKU title to set header title tag? I want to solve this problem. I want to Dynamically change title

1 Answer 1


Create a custom module.




<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Cavendish_ProductPageTitle" setup_version="1.0.0" />


<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
   <event name="layout_generate_blocks_before">
      <observer name="product_page_title_change" instance="Cavendish\ProductPageTitle\Observer\ChangeProductPageTitle"/>



namespace Cavendish\ProductPageTitle\Observer;

use Magento\Framework\Event\ObserverInterface;
use Magento\Framework\Exception\CouldNotSaveException;

class ChangeProductPageTitle implements ObserverInterface
    protected $registry;

    public function __construct(
    \Magento\Framework\Registry $registry   
    ) {
        $this->registry = $registry; 

    public function execute(\Magento\Framework\Event\Observer $observer)
        $full_action_name = $observer->getFullActionName();

        if($full_action_name != 'catalog_product_view'){
            return $this;
        $product = $this->registry->registry('current_product');
            $title = $product->getMetaTitle();
            $sku = $product->getSku();
            $product->setMetaTitle($title." - ".$sku);// $product->setMetaTitle('Your Title For Product Page');
       return $this;   
  • There is some issue :- 1 exception(s): Exception #0 (ReflectionException): Class [Vendor][Module]\Observer\ChangeProductPageTitle does not exist Jan 21, 2021 at 7:13
  • It's mean not clear @klaus :( what does mean 230 character in body?? Jan 21, 2021 at 7:18
  • Share your files and code here. Jan 21, 2021 at 13:26
  • Checkout This link :- imgur.com/a/GwCzpRa last image dicomple error Jan 22, 2021 at 7:22
  • You need to replace "[Vendor]" and "[Module]" words with your chosen name. Anyways check out the updated answer. Jan 23, 2021 at 13:04

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.