Tagged: 

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #996928

    Hi, I have these instructions:

    This code should be placed in your HTML just before the </body> tag (near the bottom of your HTML file). I highlighted the name of the external JS file.

    <script type=”text/javascript”>
    function downloadJSAtOnload() {
    var element = document.createElement(“script”);
    element.src = “defer.js”;
    document.body.appendChild(element);
    }
    if (window.addEventListener)
    window.addEventListener(“load”, downloadJSAtOnload, false);
    else if (window.attachEvent)
    window.attachEvent(“onload”, downloadJSAtOnload);
    else window.onload = downloadJSAtOnload;
    </script>

    So how can I do that and where do I find the </body> tag?

    #996986

    Hey ibmethatswhoib,

    Please try this at the bottom of the functions.php file in your child theme:

    function ibmethatswhoib_add_custom_code(){ 
    ?>
    <script type=”text/javascript”>
    function downloadJSAtOnload() {
    var element = document.createElement(“script”);
    element.src = “defer.js”;
    document.body.appendChild(element);
    }
    if (window.addEventListener)
    window.addEventListener(“load”, downloadJSAtOnload, false);
    else if (window.attachEvent)
    window.attachEvent(“onload”, downloadJSAtOnload);
    else window.onload = downloadJSAtOnload;
    </script>
    <?php 
    }
    add_action('wp_footer', 'ibmethatswhoib_add_custom_code');

    Best regards,
    Rikard

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.