2

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?

2
  • What is Joomla's version and what template are you using?
    – Mikan
    Nov 18, 2016 at 22:48
  • Joomla 3.5 and the template is Cloudbase3
    – Jepessen
    Nov 18, 2016 at 23:02

1 Answer 1

7

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):

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

    // AdSense code begins:
    <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
    <!-- Homepage Leaderboard -->
    <ins class="adsbygoogle"
    style="display:inline-block;width:728px;height:90px"
    data-ad-client="ca-pub-1234567890123456"
    data-ad-slot="1234567890"></ins>
    <script>
    (adsbygoogle = window.adsbygoogle || []).push({});
    </script>
    // AdSense code ends.

</body>

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.