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.

  • Did you solve this? Dec 18, 2018 at 4:16
  • @themanwhoknowstheman see below :)
    – Mageinn
    Dec 20, 2018 at 10:06

1 Answer 1


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.

  • Feel like a plugin should be able to more simply handle this but haven't figured one out yet.
    – addMitt
    Apr 16, 2021 at 19:46

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.