Add script just after <head>

by Jepessen   Last Updated November 08, 2018 09:10 AM

I'm registering to Google AdSense. In order to check the site they want that I put a piece of code inside (<script>something</script>) just after <head> tag.

How can I do it?

Answers 1

First, according to the docs AdSense code doesn't go after the <head>, it goes between the <body> tags. JavaScript should almost always be placed at the end of the body, just before </body>, so slow-loading scripts don't hold up the rest of your page (in this case, however, the script is loaded asynchronously so that shouldn't be much of an issue. Still, Google's docs have it at the bottom of the body and it's considered best practice to put any external scripts there, so that's what I'd do).

You want to add the script to the index.php of the site template(s) you'll be using. If I was using the default Protostar template, for example, I'd edit .../templates/protostar/index.php like so (I've used the same script code from the docs I linked to above, replace that with your own AdSense code):

    <jdoc:include type="modules" name="debug" style="none" />

    // AdSense code begins:
    <script async src="//"></script>
    <!-- Homepage Leaderboard -->
    <ins class="adsbygoogle"
    (adsbygoogle = window.adsbygoogle || []).push({});
    // AdSense code ends.


Do the equivalent for your Cloudbase3 template and it should hopefully work for you.

November 19, 2016 01:20 AM

Related Questions

Updated April 07, 2015 23:04 PM

Updated June 18, 2015 23:04 PM

Updated June 10, 2015 22:04 PM

Updated November 25, 2016 08:04 AM

Updated March 10, 2017 03:10 AM