3

Some of the pages show incorrect title and heading : it is showing "Customer Login" as page heading and title for Contact page and Advanced Search page.

The point is, I included customer login form on every page including these above, but anywhere else I can edit the page title successfully...

How to edit these pages title and heading ?

  • Have you installed any third party extension for Customer login like login with facebook etc? – mageDev0688 Jun 29 '17 at 9:42
  • Nope, but I've a custom theme that shows a customer login form in header on every pages. The weirdest thing is that on every pages but these two, I can change the page title easily... – Thomas Domingues Jun 29 '17 at 9:45
  • So you want to change only Contact page and Advanced Search page titles? – mageDev0688 Jun 29 '17 at 9:48
  • Not only, but yes, I want to change these pages title. I tried to add this snippet : <referenceBlock name="page.main.title"> <action method="setPageTitle"> <argument translate="true" name="title" xsi:type="string">BLAH BLAH</argument> </action> </referenceBlock> in contact_index_index.xml but it didn't work. – Thomas Domingues Jun 29 '17 at 9:49
  • What is the location of this file contact_index_index.xml this should be in /app/design/frontend/Vendor/ThemeName/Magento_Contact/layout. – mageDev0688 Jun 29 '17 at 10:00
5

Solved it. The problem was that I had a layout using Magento\Customer\Block\Form\Login, like this:

<block class="Magento\Customer\Block\Form\Login" name="login.sidebar" template="form/login_sidebar.phtml">
    <container name="form.additional.info" as="form_additional_info"/>
</block>

I saw that Magento\Customer\Block\Form\Login class was overriding _prepareLayout() function like this:

/**
 * @return $this
 */
protected function _prepareLayout()
{
    $this->pageConfig->getTitle()->set(__('Customer Login'));
    return parent::_prepareLayout();
}

So I created a custom Block in app/code/MyVendor/MyModule/Block/Form/Login extending Magento\Customer\Block\Form\Loginand overriding _prepareLayout() function like this:

<?php

namespace MyVendor\MyModule\Block\Form;

use Magento\Customer\Block\Form\Login as BaseLogin;

class Login extends BaseLogin
{
    /**
     * @return $this
     */
    protected function _prepareLayout()
    {
        return $this;
    }
}

And then I replaced in my custom layout this:

<block class="Magento\Customer\Block\Form\Login" name="login.sidebar" template="form/login_sidebar.phtml">
    <container name="form.additional.info" as="form_additional_info"/>
</block>

by that:

<block class="MyVendor\MyModule\Block\Form\Login" name="login.sidebar" template="Magento_Customer::form/login_sidebar.phtml">
    <container name="form.additional.info" as="form_additional_info"/>
</block>

And the issue was solved!

  • I try it above code its working fine for affected pages but it also removes the title from customer login page. – Devidas Jul 3 '18 at 13:40

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.