Wondering if this will always be free?  See why free is better.

Main Menu

Add google adsense code within Head html beacon

Started by dabigben, October 14, 2018, 10:57:42 AM

Previous topic - Next topic



I would like to try the new automated ads from google adsense in my smf forum. Basically you just put a code in the header then the ads insert themselves in the website. Google says that you only have to put the script code in the HEAD beacon, which I cannot find in the files since they are all php files. Somebody could help me understand that please ?



the head section/tag is in index.template.php, you may need to include your code in an echo statement.


Ok thanks. So I put the code in that file only ?

I don't know about php, and Have no idea what echo statement to use. Do you know if I can find an example somewhere ?  My theme is the default theme curve.



I just found the Head tag, I see there's echo tags in it. Should I add mine this way :

echo '

If so, should I put it before or after the other echos ?


it can be complicated, depending on your theme....   you don't want to put an echo inside of an existing echo...    and the adsense stuff needs to go in the <head>, not at the beginning of the file..

or you could just install a mod which does it for you...;basic_search=adsense

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."


Just wanted to check if this is still the best practice for adding Google AdSense code to an entire site (in 2022).

I'm using the Ad Management mod v3.5 for some custom made ads (and it's great!) but the mod seems to be built for placing ad code only in specific areas (top of page, various boards, etc) whereas Google AdSense has its own controls for where ads are shown that works quite well.

Can anyone clarify the best way to implement Google AdSense in SMF in 2022?

Aleksi "Lex" Kilpinen

I don't think the AdSense code implementation has changed much,
and the best place for it is still in index.template.php right before </head>.

You can also use Ad Management mod. If you are using auto ads you only need the code in one place on each page, so for example the top of the page.

"Before you allow people access to your forum, especially in an administrative position, you must be aware that that person can seriously damage your forum. Therefore, you should only allow people that you trust, implicitly, to have such access." -Douglas

How you can help SMF


If you have placed an ad code somewhere with the Ad Management Mod and enabled automatic ads in the Google Adsense console for the domain, they will be displayed. You don't necessarily need the "Automatic ads" code in the header.
Quality first


Thanks Lex! I got things working by adding the Google code manually in the index.template.php file. When I tried to use the Ad Management Mod it broke the forum:
You cannot view this attachment.
Not sure why, but at least it's working with the manual code edit.

It'd be nice if there was a simple mod for injecting code into the template file  (or other files) without having to go directly into the site files (I know it's accomplishing the same thing, but helpful for non-coders to have easier access). Maybe it's a security concern or harder to build reliable than it seems...


Have you tried Optimus? It has "Counters" tab in its settings for that.


Quote from: Bugo on April 20, 2022, 11:29:51 AMHave you tried Optimus? It has "Counters" tab in its settings for that.

No I haven't Bugo, thank you! I'll look into it. It looks like it has a few different features that could come in handy!


If you don't want to use a mod to insert a code, you have to do it yourself.

In the template in the header this is very easy...
PHP and html basic knowledge are then but needed.
Quality first


Quote from: Bugo on April 20, 2022, 11:29:51 AMHave you tried Optimus? It has "Counters" tab in its settings for that.

Bugo, I installed Optimus on a test site and you're right, it's great for adding Google AdSense code!
It's also great for adding Google Tag Manager code because you can add code in the body as well as the head (how Google Tag Manager wants it).

Two quick thoughts:
- I wonder if you've considered changing the name of the 'Counters' feature to something more related to simply adding code in general?
- I previously searched the Mods for 'AdSense' and 'Tag Manager' but didn't find Optimus. I think it showed under a search for 'Google' but it was too buried. Maybe include those terms in your Description so others can also find it? Something like 'add custom code for Google AdSense and/or Google Tag Manager' might do the trick? 

Just ideas... thanks again for the wonderful Mod!