🔥 Just Launched! Werra Premium Template for HyväSee it in Action

How to Set Page Title in Magento 2 Using Controller & XML

By Jignesh ParmarUpdated on Apr 21, 2025 2 min read

It is displayed on the top of the browser window and helps the visitors to identify the page among multiple tabs!

Unfortunately, Magento 2 custom modules take the page address and show them as page titles. That can be pretty annoying for the visitors and can make your store look unprofessional. Well, there are ways to set page titles in Magento 2 — offering a smooth and pleasant customer experience.

Recently, I stumbled upon a similar issue while working on one of my client’s website. In this blog post, I am going to share the methods that I used to set page title in Magento 2 using controller & XML.

Let’s go…!

Methods to Set Page Title in Magento 2

Use any of the two ways described below to change the page title in Magento 2.

Method #1: Set Page Title in Magento 2 Using Controller

Use this code to set the Magento 2-page title using the controller:

/** @var \Magento\Framework\View\Result\Page $resultPage */
$resultPage = $this->resultPageFactory->create();
$resultPage->getConfig()->getTitle()->set('Enter the custom page title here');

Method #2: Set Page Title in Magento 2 Using XML

Use this code in the layout module_controller_action.xml file to set page title in Magento 2:

<?xml version="1.0"?>

That’s it!

I hope now it’ll be easier for you to set the page title in Magento 2 using controller & XML.

Conclusion

Setting informative page titles is essential for any website as they help the users easily identify the pages while surfing multiple sites at once. If you are a Magento 2 developer, you can use the methods provided above to set the page title in Magento 2 using controller & XML.

If you still have any doubts or queries, feel free to comment.

I’d be happy to help!

Contribute to the community by sharing this Magento 2 tutorial through social media & online forums. (Sharing = Caring! 🙂

Thanks for reading!

Jignesh Parmar Full Image
Article byJignesh Parmar

An expert in his field, Jignesh is the team leader at Meetanshi and a certified Magento developer. His passion for Magento has inspired others in the team too. Apart from work, he is a cricket lover.