Magento – Magento2 Best practice to edit layout xml file

layoutmagento2overriding

Suppose that I want to edit the file

vendor/magento/module-theme/view/frontend/layout/default.xml

Do I edit the file directly?

It seems not a best practice to me.

Or is there anyway I can extend the file to override the content.

Best Answer

You can use the following to override the layout file. For Example, vendor/magento/module-theme/view/frontend/layout/default.xml

<vendor_theme_dir>
|__/<vendor_theme>
  |__/Magento_Theme
    |__/view
      |__/frontend
         |__/layout
            |__/default.xml

So you just need to override a file under your theme folder.

Related Topic