cancel
Showing results for 
Search instead for 
Did you mean: 

Adding script before closing body tag

Adding script before closing body tag

As the title says I'm trying to add some script before the closing body tag.

So far I have created my own vendor/theme and am referencing the magento theme module.

 

I have;

 

/my-vendor/my-theme/Magento_Theme/layout/default.xml

which contains;

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

and I have /my-vendor/my-theme/Magento_Theme/templates/html/js.phtml which contains my script.

Pretty new to this so no idea if this is nearly right, it's pieced together from various bits I have found.
Thanks

2 REPLIES 2

Re: Adding script before closing body tag

How to add a JavaScript at a Magento 2 page's end (before the closing </body> HTML tag)? https://mage2.pro/t/811

Re: Adding script before closing body tag

? That does not help