I have been scouring the forums for the right way of changing the page title for a specific page or layout in Magento 2 but many answers rely on action methods which are now deprecated.

Essentially, I have set the store up so the suffix for each page title is "- CompanyName" but I would like to know how to create an exception for this for the home page (and other specific landing pages). I have changed the page title in a custom layout file successfully but the suffix is still appended to the end. Is there a sensible way of stopping this from happening on a specific page, like the home page?

Thank you.


You need to overwrite Magento\Framework\View\Page\Title::addConfigValues function.


<?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="YourVendor_YourModule" setup_version="1.0.0">
            <module name="Magento_Framework"/>


<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <preference for="Magento\Framework\View\Page\Title" type="YourVendor\YourModule\Model\View\Page\Title" />


namespace YourVendor\YourModule\Model\View\Page;

* Page title
* @api
* @since 100.0.2
class Title extends \Magento\Framework\View\Page\Title
     * @var \Magento\Framework\App\Config\ScopeConfigInterface
    private $scopeConfig;

     * @var \Magento\Framework\App\Request\Http
    private $request;

     * Title constructor.
     * @param \Magento\Framework\App\Request\Http $request
     * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
    public function __construct(
        \Magento\Framework\App\Request\Http $request,
        \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
    ) {
        $this->request = $request;
        $this->scopeConfig = $scopeConfig;


     * @param string $title
     * @return string
    protected function addConfigValues($title)
        $preparedTitle = $this->scopeConfig->getValue(
            ) . ' ' . $title;
        $postfix = ' ' . $this->scopeConfig->getValue(
        if ($this->request->getFullActionName() == 'cms_index_index') {
            $postfix = '';
        return trim($preparedTitle . $postfix);

Replace YourVendor_YourModule with your own vendor and module names.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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