In one Magento 2.2.6 instance something very odd occurs: the meta page title shows

<title>Customer Login</title>

and the page title in the content also shows Customer Login - even though the route has nothing to to with the customer login!

The module in question is omikron/magento2-factfinder and the route in question is factfinder/result/index. Currently the extension does not set its own page title (I've already created a PR for that), but even when you add

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
        <title>Search Results</title>

the page still shows <title>Customer Login</title> in the meta tags - however the page title in the <body> will indeed show Search Results.

In a second Magento 2.2.6 instance this problem does not occur.

How can this be? What could be the reason why the page title is overridden in such a manner for a particular route?

1 Answer 1


This is something I've seen on Magento 1 before.
I have a hunch that you have a login form displayed in every page.
Something like a popup that appears when you click on the 'login' button, or something like that.
If this is the case, the problem is cause by that login form.
I assume the block class that displays the mini-form is Magento\Customer\Block\Form\Login or a class that extends it.
This class has a method called _prepareLayout which is called automatically for each block before the block is rendered.

For the login class, the method looks like this:

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

This means, that every page that contains this block will get the meta title Customer Login.

You have 2 options here (there may be more):
Option 1: the clean way.

Create a class that extends Magento\Customer\Block\Form\Login. Your new class should contain a single method

 * @return $this
protected function _prepareLayout()
    return $this;

Then, use this new class in the layout for the mini-login form.

Option 2: quick and dirty.
Same as in option 1, create the same class, then in the di.xml file of your module set a preference for the default login block to your new class

<preference for="Magento\Customer\Block\Form\Login" type="Your\NewClass\Name\Here" />

This should work also, but you might lose the meta title on the actual login page.

As a note: this is a magento inconsistency. the login class knows and does too much. It knows details about the context that it should not know.

  • You are right! There is indeed a login block present on every page (to show a login overlay, when clicking a "login" button). However, what I do not understand is: why is this problem not occurring on every page? Regular magento routes or routes of other modules do not seem to be affected. Just the custom route from this module.
    – fritzmg
    Dec 17, 2018 at 10:19
  • maybe for other pages there is a call to pageConfig->getTitle()->set(...) done after _prepareLayout is executed.
    – Marius
    Dec 17, 2018 at 10:28
  • May be, yeah. Anyway your solution worked (I used option 1) :)
    – fritzmg
    Dec 17, 2018 at 13:31

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.