{"id":2678,"date":"2024-12-31T20:26:01","date_gmt":"2024-12-31T20:26:01","guid":{"rendered":"https:\/\/meetanshi.com\/blog\/how-to-set-page-title-in-magento-2-using-controller-xml\/"},"modified":"2025-07-23T09:38:51","modified_gmt":"2025-07-23T04:08:51","slug":"set-page-title-in-magento-2-using-controller-xml","status":"publish","type":"post","link":"https:\/\/meetanshi.com\/blog\/set-page-title-in-magento-2-using-controller-xml\/","title":{"rendered":"How to Set Page Title in Magento 2 Using Controller &#038; XML"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">It is displayed on the top of the browser window and helps the visitors to identify the page among multiple tabs!  <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Unfortunately, <a title=\"Magento Commerce\" href=\"https:\/\/business.adobe.com\/products\/magento\/magento-commerce.html\" target=\"_blank\" rel=\"noopener\">Magento 2<\/a> 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 \u2014 offering a smooth and <a title=\"Magento 2 Extensions for Customer Experience\" href=\"https:\/\/meetanshi.com\/blog\/magento-2-extensions-for-improved-customer-experience\/\" target=\"_blank\" rel=\"noopener\">pleasant customer experience<\/a>.  <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Recently, I stumbled upon a similar issue while working on one of my client&#8217;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 &amp;<em><strong> <\/strong><\/em>XML.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Let&#8217;s go&#8230;!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"methodstosetpagetitleinmagento2\">Methods to Set Page Title in Magento 2<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Use any of the two ways described below to change the page title in Magento 2.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"setpagetitleinmagento2usingcontroller\">Method #1: Set Page Title in Magento 2 Using Controller<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Use this code to set the Magento 2-page title using the controller:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/** @var \\Magento\\Framework\\View\\Result\\Page $resultPage *\/\n$resultPage = $this->resultPageFactory->create();\n$resultPage->getConfig()->getTitle()->set('Enter the custom page title here');<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"setpagetitleinmagento2usingxml\">Method #2: Set Page Title in Magento 2 Using XML<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Use this code in the layout module_controller_action.xml file to set page title in Magento 2:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?xml version=\"1.0\"?><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">That&#8217;s it!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I hope now it&#8217;ll be easier for you to set the page title in Magento 2 using controller &amp; XML.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"conclusion\">Conclusion<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">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 <a title=\"Magento 2 developer\" href=\"https:\/\/meetanshi.com\/hire-magento-developer.html\" target=\"_blank\" rel=\"noopener\">Magento 2 developer<\/a>, you can use the methods provided above to set the page title in Magento 2 using controller &amp; XML.  <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you still have any doubts or queries, feel free to comment.  <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I&#8217;d be happy to help!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Contribute to the community by sharing this Magento 2 tutorial through social media &amp; online forums. (Sharing = Caring! \ud83d\ude42<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Thanks for reading!  <\/p>\n","protected":false},"excerpt":{"rendered":"<p>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&#8230;<\/p>\n","protected":false},"author":13,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[34],"tags":[],"class_list":["post-2678","post","type-post","status-publish","format-standard","hentry","category-magento"],"acf":[],"_links":{"self":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/2678","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/users\/13"}],"replies":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/comments?post=2678"}],"version-history":[{"count":5,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/2678\/revisions"}],"predecessor-version":[{"id":19090,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/2678\/revisions\/19090"}],"wp:attachment":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/media?parent=2678"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/categories?post=2678"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/tags?post=2678"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}