Tutorial: Adding Adsense to your site
Posted: 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
Lets say you want to show one ad for guests and a different ad for registered users.
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
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.
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 -->
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 -->
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 -->
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.