Digital Inspiration

about us faq contact

How to Display Just One Google Adsense Ad on Blogger MainPage

DI regular Kaileena of Celeb Gossips writes in - "I want to place an Adsense ad unit on my blogspot blog after the first post only like you have done."

Before we get to the Blogger Template code, let's look at the requirement in detail.

As most Blogspot users know already that with Blogger, if you add an Adsense ad unit after the first blog post, the ad unit will appear after the next two posts as well because the template mechanism replicates whatever code it finds inside the <Blogger> tags.

[Though visitors see only three ad units as Google Adsense technology automatically blocks serving more than three ads on a single webpage.]


To prevent this and ensure that only one Adsense Ad unit appears between your first and second blog posts on the mainpage (like in the above screenshot), you will have to slightly change the method of writing Adsense code via javascript.

Step 1: Add the following javascript snippet inside the <head> tag.

<head>
.....
<script type="text/javascript">googleadcount=1;</script>
.....
</head>

Step 2: Copy your Adsense code generated from the Adsense control panel and append it your Blogger template as shown below:

<MainPage>
<div class="post-body">
.....
<$BlogItemBody$>
.....
<script type="text/javascript"><!--
google_ad_client = "pub-xxx"
google_ad_width = 468;google_ad_height = 60;
.....
//--></script>

<script type="text/javascript">

if (googleadcount==1) {
  document.write('<script type="text\/javascript"
  src="http:\/\/pagead2.googlesyndication.com\/pagead\/show_ads.js"><\/script>');
  googleadcount++;
  }

</script>
</MainPage>

The magical role is played by the variable googleadcount that we defined in Step 1. If the value of this variable is more than 1 (meaning an ad has already been displayed), it would skip displaying subsequent ads on your Blogger MainPage or ArchivePage.

Important Note: Since modifying Adsense generated code is against Adsense TOS, I strongly suggest that you obtain permission from Google before implementing the above solution.

Related Adsense Case Studies: Scott Hanselman Blog, Rashmi Bansal

Email This   Print Article   Save as PDF   Subscribe   Translate 


Download Free Google Software:


Reader Comments:

Thanks a lot Amit :)

Isn' t that against the TOS, I mean using escape characters within adsense code?

Good tweak there I have done similar things for adsense under https at http://www.idealwebtools.com/blog/adsense-ssl/

Great tweak amit

thanks

I think, it's very helpful for everybody using blogger.com. but i am using beta.blogger. when i try to copy the adsense script inside the body, it doesn't accept. can you help me put the ads like your in my beta.blogger. my blog address is http://topaix.blogspot.com Thanks in advance.

I've been able to display the adsense. Then I tried the javascript, but it gave me something like this

Your template could not be parsed as it is not well-formed.

i have no idea about this, Can you help me? :) thx.

Have a question? Need help? Visit the forums ».

Search For More Stories

Google Custom Search

subscribe

Get our E-Mail Newsletter

Subscribe in a reader


Quick Facts & Statistics

Digital Inspiration is a popular technology website with more than 5000 articles, tutorials and how-to guides related to software, computers, and internet.

The site launched in 2004 and averages over 2 million page views per month ..read more

Digital Inspiration Community on Google Maps
Support Forums


 

© 2008 Digital Inspiration - Technology, à la Carte | Mobile Edition | Videos | Tech Support | Terms

The articles are copyrighted to Amit Agarwal and can only be reproduced given the author's permission.


Skip to top of the page ^^