Change Structure of Magento Product Meta Title

Change Structure of Magento Product Meta Title

October 16, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Change Structure of Magento Product Meta Title

Changing Magento Product Meta Title Structure Without Overwriting Updates

Hello developers! Today, I want to guide you through changing the structure of your Magento product meta titles without worrying about updates overwriting your changes. Let’s dive right in.

Current Default Behavior

By default, Magento uses a fixed format for product meta titles: [PRODUCT_NAME] | [PRODUCT_CATEGORY]. This is determined by the getMetaTitle() method in Mage/Catalog/Model/Product.php.

public function getMetaTitle()
{
    return trim($this->getName() . ' | ' . $this->getCategory());
}

The Challenge

The issue arises because this logic is hardcoded within Magento’s core files. If you change the format here and then update Magento, your changes will be overwritten.

For example, if you try to modify the getMetaTitle() method directly:

public function getMetaTitle()
{
    return trim($this->getName());
}

…and later update Magento, this code will be reverted back to the original logic.

The Solution: Observer Events

To solve this, we’ll use an event observer. Magento allows you to listen for events and execute custom logic when they occur.

Step 1: Create an Event Observer File

Create a new PHP file in your module’s etc/events.xml directory (create the folder if it doesn’t exist). In this XML file, you can define which events you want to observe.

<?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="catalog_product_get_name_after">
        <observer name="custom_magento_product_meta_title" instance="Vendor_Modulename\Observer\ProductGetNameAfter" />
    </event>
</config>

In this example, we’re observing the catalog_product_get_name_after event. This event triggers after Magento retrieves a product’s name.

Step 2: Create the Observer Class

Now create the observer class:

<?php

namespace Vendor_Modulename\Observer;

use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;

class ProductGetNameAfter implements ObserverInterface
{
    public function execute(Observer $observer)
    {
        $product = $observer->getProduct();
        $product->setData('meta_title', trim($product->getName()));
    }
}

Here, we’re checking for the catalog_product_get_name_after event. When it triggers, we retrieve the product and set its meta title to just the product name using trim().

The Result

With this setup, whenever a product’s name is accessed after Magento 2 has retrieved it, our observer will automatically set the meta title to be just the product name.

This solution is robust because it doesn’t modify any core files or methods. It relies on Magento’s event system, which means your changes won’t be overwritten by updates.

Conclusion

Changing the behavior of hardcoded functions in Magento can indeed be tricky due to the risk of updates overwriting them. However, using observer events provides a clean and safe way around this issue.

This approach maintains the flexibility of customization without compromising the stability and upgradability of your Magento site. It’s a powerful technique that every Magento developer should have in their toolkit.

Remember to replace Vendor_Modulename with your actual vendor name. For more advanced techniques like this, check out our Magento Developer Guide at Laravel Company.

Happy coding! Let me know if you need any further assistance or have other questions about Magento development.

Catalog Extensions Configuration SEO

Our network