Tutorial: Adding Adsense to your site

Do not post support requests, bug reports or feature requests. Discuss phpBB here. Non-phpBB related discussion goes in General Discussion!
Scam Warning
Post Reply
wrkalot
Registered User
Posts: 108
Joined: Tue Oct 02, 2012 10:07 pm

Tutorial: Adding Adsense to your site

Post by wrkalot » Sun Apr 02, 2017 1:36 pm

First let me say this: There are extensions available for this purpose. If you don't want to try my method, go to the extension for and do a search. I had special needs in regards to the ad placements and find that this method work perfectly for my needs.

I have tested on 3.1.x and 3.2.x and have found zero issues

For me, and many forum owners, advertising is needed in order to support the development of their site, and often supplies weekend beer money. I always see questions posted on how to add ads and have been wanting to write a short tutorial on what's worked for me. I hope this helps others in there effort to monetize their forum.

This works with ProSilver. I am also using it with 2 of Arty's styles: Elegance and Basic with zero issues. Your mileage may vary.

The extensions listed in this post are not mine and I offer no support for them. Use at your own risk!!!

1) First download and install this: https://github.com/marttiphpbb/phpbb-ext-templateevents
Once installed it will allow any admin to show/hid the location of every template event on every front end page of the forum. This little gem, when activated, will display the template event name and location on your forum. This will come in handy as you look for the best location for your ads

2) Download and install this: https://github.com/marttiphpbb/phpbb-ex ... mplatecode
This little extension is small and simple and does exactly what what the name implies. It inserts your code in any template event.

3) OPTIONAL: Download and install this: https://github.com/marttiphpbb/phpbb-ext-grouptempvars
Lest say that you don't want to show ads to a special user group(s). This little gem will allow to to show/hide ads depending on the users default group ID

ALL of your custom code (your ad code) will reside in the event directory here forumroot>ext>marttiphpbb>inserttemplatecode>styles>all>template>event

Go to forumroot>ext>marttiphpbb>inserttemplatecode>styles>all>template>event. It comes installed with a few events but the real beauty here is that you can add any event you want, but we'll start with something simple.

1) If there is no overall_header_content_before.html in the event directory, create one.
2) Paste you ad code into overall_header_content_before.html, save it and upload it.

Presto! Yeah, it's that simple.

Lets take this one step further (still working with overall_header_content_before.html) Lets show the ad to guest only using IF not S_USER_LOGGED_IN

Code: Select all

<!-- IF not S_USER_LOGGED_IN -->
my ad code here
<!-- ENDIF -->
Lets say you want to show one ad for guests and a different ad for registered users.

Code: Select all

<!-- This ad shows to guests -->
<!-- IF not S_USER_LOGGED_IN -->
my ad code for guests
<!-- ELSE -->
<!-- ENDIF -->

<!-- This ad shows to registered users -->
<!-- IF not S_USER_LOGGED_IN -->
<!-- ELSE -->
my ad code for members
<!-- ENDIF -->
Now, it's up to you what to display to who, and where. It's also important to read and understand the Adsense TOS regarding the number of ad types you can have per page, where those ads can be shown, etc. I hide all ads on any upc.php page so ads wont show on login and registration pages.

I also have a special group that makes donations to support the site. I don't show ads to that group. I also what to hide certain ads on tablets and smart phones, partly because I don't always use responsive ads (at the moment).

In addition, I have added some custom CSS for borders, background colors etc but you need to decide if that need for your purposes and I won't elaborate on that.

Below is an example of what my code looks like, just for the overall_header_content_before.html template. span class="responsive-hide" will hide the ad(s) on smaller screen sizes

Code: Select all

<!-- IF SCRIPT_NAME == 'ucp' or S_GROUP_8-->
<!-- ELSE -->
<!-- IF not S_USER_LOGGED_IN -->
<span class="responsive-hide">
my ad code for guests
</span>
<!-- ELSE -->
<!-- ENDIF -->
       
<!-- IF not S_USER_LOGGED_IN -->
<!-- ELSE -->
<span class="responsive-hide">
my ad code for registered users that are not a member of my special donation group
</span>
<!-- ENDIF -->
<!-- ENDIF -->
There may very well be better ways to implement the code I have listed above. I am not a coder and don't pretend to be. If you have a cleaner way to do it please feel free to share it.

The real cool part about all of this is that you can place content, ads, whatever, "almost" anywhere there is a template event. Simply navigate to the page you want to add some stuff, show the template events on that page, create the template event in the events directory listed above, and ad your content.

Also, a big shout out to marttiphpbb for creating these extentions. While they may never be updated, they have given me tools to do some really cool stuff while leaving the core, and my style, untouched.
Last edited by wrkalot on Sat May 20, 2017 4:12 pm, edited 2 times in total.
Tutorial: How to add ads to your forum viewtopic.php?f=64&t=2417316

User avatar
Galandas
Registered User
Posts: 731
Joined: Thu Jul 23, 2009 4:11 pm
Location: Italy
Name: Rey
Contact:

Re: Tutorial: Adding Adsense to your site

Post by Galandas » Sun Apr 02, 2017 10:05 pm

guide very useful thanks
English is not my native language My CDB Contributions My RC extensions

wrkalot
Registered User
Posts: 108
Joined: Tue Oct 02, 2012 10:07 pm

Re: Tutorial: Adding Adsense to your site

Post by wrkalot » Tue Apr 04, 2017 11:30 am

Thank you. I hope some find it useful.
Tutorial: How to add ads to your forum viewtopic.php?f=64&t=2417316

wrkalot
Registered User
Posts: 108
Joined: Tue Oct 02, 2012 10:07 pm

Re: Tutorial: Adding Adsense to your site

Post by wrkalot » Sat May 20, 2017 4:11 pm

I have tested the above methods with a fresh install of 3.2.0 and have found zero issues.
Tutorial: How to add ads to your forum viewtopic.php?f=64&t=2417316

Ghostwolf308
Registered User
Posts: 38
Joined: Mon Jun 11, 2018 12:55 am

Re: Tutorial: Adding Adsense to your site

Post by Ghostwolf308 » Sun Jan 06, 2019 5:23 pm

Has this been tested since the new updates to adsense and their auto ads? I currently have it running but it is placing ads everywhere if this will take care of that I will be relieved.

Post Reply

Return to “phpBB Discussion”