I am looking for a solution to add a custom class before "main.content" for all pages remaining home page. Currently, I am doing below code

<referenceContainer name="page.wrapper">
           <container name="your.custom.name" as="your-custom" label="Your Label Name" htmlTag="div" htmlClass="custom_class" htmlId="your-id" before="page-footer"/>
  <move element="main.content" destination="your.custom.name"/>

in default.xml.

but this code adding "custom_class" class for all pages. I want to exclude from the home page. Please suggest if anyone has an idea.


Remove your.custom.name container from the cms_index_index.xml file placed under Magento_Theme/layout/cms_index_index.xml with below content.

<referenceContainer name="your.custom.name" remove="1" />


Add below content in Magento_Theme/layout/cms_index_index.xml file.

<referenceContainer name="page.wrapper">
       <container name="your.custom.name" as="your-custom" htmlTag="div" before="page-footer"/>
<move element="main.content" destination="your.custom.name"/>

Hope this helps!!!

  • @summit,It is working but this is removing all div under custom class including "main.content" so home page totally distruct.I want remove only class name not totally div. – akgola Sep 16 '19 at 6:51
  • Add <move element="main.content" destination="page.wrapper"/> in cms_index_index.xml file. – Sumit Sep 16 '19 at 6:55
  • @summit,I have tried but still not got any success,I just want to add class for all page before main.content and remove it for cms page.so if you have any other idea please share me. – akgola Sep 16 '19 at 8:01
  • I've updated my answer, you can remove the class and id from the custom container with my updated code. Also, you can add your own custom class which is only used on the home page. For example: htmlClass="test" in the container tag. Please review. – Sumit Sep 16 '19 at 9:16
  • 1
    @summit,Working perfectly its overriding default.xml class with dummy class. – akgola Sep 16 '19 at 10:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.