{"id":502,"date":"2019-07-10T22:30:12","date_gmt":"2019-07-10T22:30:12","guid":{"rendered":"https:\/\/meetanshi.com\/blog\/2019\/07\/10\/override-phtml-file-using-custom-module-in-magento-2\/"},"modified":"2025-09-01T11:48:30","modified_gmt":"2025-09-01T06:18:30","slug":"override-phtml-file-using-custom-module-in-magento-2","status":"publish","type":"post","link":"https:\/\/meetanshi.com\/blog\/override-phtml-file-using-custom-module-in-magento-2\/","title":{"rendered":"How to Override a phtml File Using a Custom Module in Magento 2"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">It is well known that customizing the core Magento 2 functionality is a bad coding practice. Once you\u00a0<a href=\"https:\/\/meetanshi.com\/magento-upgrade-service.html\" target=\"_blank\" rel=\"noreferrer noopener\">upgrade the Magento version<\/a>, your efforts are in vain. Hence, it is advisable to override a function, class or file, as per the requirement.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here, I\u2019ll show you how to&nbsp;override a phtml file using a custom module in Magento 2.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">There are two methods to do so as mentioned below:<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Methods to Override a phtml file using a custom module in Magento 2:<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">1. Create file registration.php at app\/code\/Vendor\/Extension\/ folder<\/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;?php\n\\Magento\\Framework\\Component\\ComponentRegistrar::register(\n    \\Magento\\Framework\\Component\\ComponentRegistrar::MODULE,\n    'Vendor_Extension',\n    __DIR__\n);<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">2. Create module.xml file at app\/code\/Vendor\/Extension\/etc\/ folder<\/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\"?>\n&lt;config xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\"\n        xsi:noNamespaceSchemaLocation=\"urn:magento:framework:Module\/etc\/module.xsd\">\n    &lt;module name=\"Vendor_Extension\" setup_version=\"1.0.0\">\n    &lt;\/module>\n&lt;\/config><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">3. Create file customer_account_create.xml at app\/code\/Vendor\/Extension\/view\/frontend\/layout\/ folder<\/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\"?>\n&lt;page xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"urn:magento:framework:View\/Layout\/etc\/page_configuration.xsd\">\n    &lt;body>\n        &lt;referenceBlock name=\"customer_form_register\">\n            &lt;action method=\"setTemplate\">\n                &lt;argument name=\"template\" xsi:type=\"string\">Vendor_Extension::form\/register.phtml&lt;\/argument>\n            &lt;\/action>\n        &lt;\/referenceBlock>\n    &lt;\/body>\n&lt;\/page><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">now you need to create register.phtml at location app\/code\/Vendor\/Extension\/view\/frontend\/templates\/form\/<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">That\u2019s it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The above example shows how to override a phtml file for customer register page. The default functionality to show out of stock is overridden to display an image.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Follow any of the above method suitable to you.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Thank you.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>It is well known that customizing the core Magento 2 functionality is a bad coding practice. Once you\u00a0upgrade the Magento version, your efforts are in&#8230;<\/p>\n","protected":false},"author":5,"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-502","post","type-post","status-publish","format-standard","hentry","category-magento"],"acf":[],"_links":{"self":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/502","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\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/comments?post=502"}],"version-history":[{"count":5,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/502\/revisions"}],"predecessor-version":[{"id":21416,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/502\/revisions\/21416"}],"wp:attachment":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/media?parent=502"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/categories?post=502"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/tags?post=502"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}