2

I'm using magento 2 , and I would need to add some content before the body closing tag , on every page. What's the most correct way to do that ?

3 Answers 3

3

You can use before.body.end as the reference name and add the block using layout/default xml

Here is an example: Magento 2 add script before closing body tag

Look at KAndy's answer.

2

you can simply add block with xml add this in default.xml

<referenceContainer name="before.body.end">
            <block class="Magento\Framework\View\Element\Template" name="beforebody"  template="Magento_Theme::beforebody.phtml"/>
</referenceContainer>

reference

1

One possibility is via the Magento Admin:

Admin -> Stores -> Configuration -> Design -> Footer -> Miscellaneous HTML

Another option via the Magento Admin is to use a widget to include a static block:

Admin -> Content -> Widget: CMS Static Block
  Layout Updates: 
     Display on: All Pages
     Container: Page Bottom

If creating/customizing a theme then you could consider using layout XML to include a template or static block.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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