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
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.
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>
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.