I'm creating a simple page in my Magento 2 instance.
in the controller for that page I'm trying to set a title for the page and a meta title that should be different.
But I'm not able to do that.
My layout file for the action is almost empty:
<page layout="1column" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
</body>
</page>
and my controller action looks like this:
namespace [Namespace]\[Module]\Controller\[Entity];
use Magento\Framework\App\Action\Action;
use Magento\Framework\App\Action\Context;
use Magento\Framework\View\Result\PageFactory;
class Index extends Action
{
protected $resultPageFactory;
public function __construct(
Context $context,
PageFactory $resultPageFactory
) {
parent::__construct($context);
$this->resultPageFactory = $resultPageFactory;
}
public function execute()
{
$resultPage = $this->resultPageFactory->create();
$resultPage->getConfig()->getTitle()->set('Something');
}
}
The result is this:
But the meta title is the same as the title (Something
).
Changing the line in the controller:
$resultPage->getConfig()->getTitle()->set('Something');
to
$resultPage->getConfig()->getTitle()->set('Something else');
results in the title (H1 tag) and the meta title changing to something else
.
How can I set a different meta title and a title (h1 tag) to a page