cancel
Showing results for 
Search instead for 
Did you mean: 

Add script between </body> and </html> tags

Add script between </body> and </html> tags

I'm trying to add some script to every page, I know you can add it just before the </body> tag but I need it after, just before the </html>.

Is there a way to do this safely?

 

Many thanks

1 REPLY 1

Re: Add script between </body> and </html> tags

You need to overwrite the file app/code/Magento/Theme/view/base/templates/root.phtml

When you open this file you will see something look like:
<!doctype html>
<html <?php echo $htmlAttributes ?>>
    <head <?php echo $headAttributes ?>>
        <?php echo $requireJs ?>
        <?php echo $headContent ?>
        <?php echo $headAdditional ?>
    </head>
    <body data-container="body" data-mage-init='{"loaderAjax": {}, "loader": { "icon": "<?php echo $loaderIcon; ?>"}}' <?php echo $bodyAttributes ?>>
        <?php echo $layoutContent ?>
    </body>

<!-- BUT YOUR'S SCRIPTS HERE-->
</html>

 

You can overwrite this file by create new theme, and put this file in app/design/frontend/Vendor/ThemeName/Magento_Theme/templates/root.phtml