Responsive AdSense

Responsive AdSense

@Brogan - is this resource up to date? It seems Google adsense has changed the code a bit. It looks like this with the new asynchronous ads, honestly, I can't get it right with your description, the ads are cut off - etc:

Code:
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- Forum home header large -->
<ins class="adsbygoogle"
     style="display:inline-block;width:728px;height:90px"
     data-ad-client="ca-pub-255xxxxxxxx"
     data-ad-slot="797xxxxxxx"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
 
I am having an issue after creating new ads to responsive. The horizontal works fine on an iPhone (no CSS) but i can't get the vertical to work right with the CSS. I have a sidebar so it shortens my top of the form area a bit. Also i had a nice 336x280 ad after first thread, I can't get it to work - it keeps displaying a 728x90 for some reason, no CSS. here was my old code that resized fine, but the ads were cut off and crappy looking in responsive mode.

Footer

Code:
<xen:hook name="ad_below_content" /><center><script type="text/javascript"><!--

google_ad_client = "ca-pub-255xxxxxxxx";

width = document.documentElement.clientWidth;

/* below content - forum 2 */

google_ad_slot = "16xxxxxxx";

google_ad_width = 300;

google_ad_height = 45;

if (width > 483) {

/* below content - forum 1 */

google_ad_slot = "16xxxxxxxx";

                google_ad_width = 525;

                google_ad_height = 60;

                }

                    if (width > 743) {

                    /* below content - forum  */

                    google_ad_slot = "16xxxxxxxx";

                    google_ad_width = 728;

                    google_ad_height = 90;

                    }

//-->

</script>

<script type="text/javascript"

src="http://pagead2.googlesyndication.com/pagead/show_ads.js">

</script></center><br />

Header Area (under breadcrumb)

Code:
<xen:hook name="ad_above_top_breadcrumb" /><br />
<center><script type="text/javascript"><!--
google_ad_client = "ca-pub-25xxxxxxx";
width = document.documentElement.clientWidth;
/* Forum home header large 2 */
google_ad_slot = "79xxxxxx";
google_ad_width = 300;
google_ad_height = 45;
if (width > 483) {
/* Forum home header large 1 */
                google_ad_slot = "79xxxxxxxx";
                google_ad_width = 525;
                google_ad_height = 60;
                 }
                    if (width > 743) {
                     /* Forum home header large */
                    google_ad_slot = "79xxxxxxxx";
                    google_ad_width = 728;
                    google_ad_height = 90;
                    }
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></center><br />

After first post

Code:
<xen:hook name="ad_above_top_breadcrumb" /><br />
<center><script type="text/javascript"><!--
google_ad_client = "ca-pub-25xxxxxxxxx";
width = document.documentElement.clientWidth;
/* Forum home header large 2 */
google_ad_slot = "79xxxxxxxx";
google_ad_width = 300;
google_ad_height = 45;
if (width > 483) {
/* Forum home header large 1 */
                google_ad_slot = "79xxxxxxxx";
                google_ad_width = 525;
                google_ad_height = 60;
                 }
                    if (width > 743) {
                     /* Forum home header large */
                    google_ad_slot = "79xxxxxx";
                    google_ad_width = 728;
                    google_ad_height = 90;
                    }
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></center><br />
 
Brogan updated Responsive AdSense with a new update entry:

Prevent advertisements from being displayed on specific pages

In order to avoid breaching Google's ToS for AdSense, certain pages should not have ads displayed on them.

This includes error pages, for example: http://cliptheapex.com/error

This can be achieved by using a standard conditional statement like so:
Rich (BB code):
<xen:if is="!in_array({$contentTemplate}, array('', 'message_page', 'error', 'search_form', 'search_form_post', 'search_form_profile_post', 'search_results',...

Read the rest of this update entry...
 
What template do you put this code in?

Code:
<xen:if is="!in_array({$contentTemplate}, array('', 'message_page', 'error', 'search_form', 'search_form_post', 'search_form_profile_post', 'search_results',...
 
Hoping someone scan help - When adding the code below content (footer) it breaks my footer. Here is the code i am using.

Code:
<style>
.footer { width: 320px; height: 50px; }
@media(min-width: 500px) { .footer { width: 468px; height: 60px; } }
@media(min-width: 800px) { .footer { width: 728px; height: 90px; } }
</style>
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- footer -->
<ins class="adsbygoogle footer"
     style="display:inline-block"
     data-ad-client="ca-pub-2556590227571531"
     data-ad-slot="6672415453"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>

Screen Shot 2014-01-01 at 10.25.32 AM.webp
 
How would I do it with this?

Code:
<center><script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<ins class="adsbygoogle"
     style="display:inline-block;width:728px;height:90px"
     data-ad-client="ca-pub-6026720746799933"
     data-ad-slot="3141788004"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script></center>
 
@Brogan

Is it possible to modify this code so i can disable to show the ads if width is less then 800 px?

HTML:
<xen:if is="!in_array({$contentTemplate}, array('', 'message_page', 'error', 'search_form', 'search_form_post', 'search_form_profile_post', 'search_results', 'register_form', 'login', 'error_with_login', 'contact'))">
Ad code here
</xen:if>
I want to use that with the DFP ads so i don't mess up my responsive design with non-responsive ads.
Thanks!
 
Hoping someone scan help - When adding the code below content (footer) it breaks my footer. Here is the code i am using.

Code:
<style>
.footer { width: 320px; height: 50px; }
@media(min-width: 500px) { .footer { width: 468px; height: 60px; } }
@media(min-width: 800px) { .footer { width: 728px; height: 90px; } }
</style>
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- footer -->
<ins class="adsbygoogle footer"
     style="display:inline-block"
     data-ad-client="ca-pub-2556590227571531"
     data-ad-slot="6672415453"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>

View attachment 63980

You can't name your ad banner "footer". If you do, change the areas in your code that do say "footer" to another name because there is already a default class named footer.
 
Last edited:
@Brogan , I was trying to figure out a way know what is the template name of the xenforo page I'm currently on and I think this is it:

- Look at source (Ctrl+U) of the page and search for: <div id="content" class="
- Whatever goes after that is the the name of the page (<div id="content" class="PAGE_NAME">).

Are there times when this wouldn't work? If that sounds good maybe you can add similar guide to your resource to help others find it (If it already does not exist).

Thanks!
 
Back
Top Bottom