Note: Be aware that Google AdSense allows a maximum of three AdSense for Content ads on one page. If you have no other AdSense ads on your blog, you may want to go into Blogger Settings and, on the Formatting tab, change the setting to Show no more than 3 posts on the main page.
If you have AdSense for Content code in your header and/or sidebar, change this value to 1 or 2 or some posts may display without an ad. Don’t forget to click Save Settings at the bottom of the Formatting tab.
Follow these instructions to learn how to display a Google AdSense ad anywhere inside a blog post.
- Get into your blog, click Layout, and click Edit HTML. Click Download Full Template to save a fresh copy of your template to disk. Then click the box next to Expand Widget Templates.
- Press Ctrl-F to bring up the "find" box. Copy <div class='post-body entry-content'> and paste it into the "find" box, and press Next. You should find the code below for most XML templates. For older templates, the code may be slightly different. <div class='post-body entry-content'> <data:post.body/> <div style='clear: both;'/> <!-- clear for photos floats --> </div>
- Place your cursor after the line <div class='post-body entry-content'> and press the Enter key 7 or 8 times.
- Then, delete the line <data:post.body/>
- Next, copy the lines of code below and paste them in the middle of the empty space you just created below the line <div class='post-body entry-content'>
<!--BEGIN Code to place ad ANYWHERE inside post-->
<div expr:id='"aim1" + data:post.id'/>
<div style='clear:both; margin:10px 0'>
<!--START of AdSense code -->
PASTE ESCAPED ADSENSE CODE HERE!
<!--END of AdSense code -->
</div>
<div expr:id='"aim2" + data:post.id'>
<data:post.body/>
</div>
<script type='text/javascript'>
var obj0=document.getElementById("aim1<data:post.id/>");
var obj1=document.getElementById("aim2<data:post.id/>");
var s=obj1.innerHTML;
var r=s.search(/\x3C!-- adsense --\x3E/igm);
if(r>0) {obj0.innerHTML=s.substr(0,r);obj1.innerHTML=s.substr(r+16);}
</script>
<!-- END OF CODE to place ad anywhere inside blog post -->
Next we must "escape" certain characters in our AdSense Ad or Blogger will not let us save the template. For instance, we must change the < sign to < - which is the ASCII equivalent. Don’t worry, this is OK with Google because you are not actually changing any code. Open a second browser window, and follow these steps:
- Go into your Google AdSense account and and find the code for your AdSense ad. Copy the code.
- Go to www.accessify.com, (will open in a separate browser tab or window) paste the code into the "Quick Escape" Tool, and click "Convert to escaped characters."
- Copy the escaped code from the "Quick Escape" box. Return to your Blogger HTML and paste this code over the line that reads PASTE ESCAPED ADSENSE CODE HERE! (*See example of what the escaped code should look like below.)
- Click Save Template.
TO SPECIFY where in the post you want the ad to display, type the following line of text:
<!-- adsense -->
It's as simple as that. If you forget to place <!-- adsense --> inside your blog post, the ad will display below the blog post title by default.
We'll cover how to position the ad (center, float left, float right) in a future post for those not familiar with HTML styles.
*Below is an example of how your AdSense ad code should look after some of the characters have been "escaped":
<script type="text/javascript"><!--
google_ad_client = "pub-9999999999999999";
/* 336x280 rect, created 9/9/09 */
google_ad_slot = "9999999999";
google_ad_width = 336;
google_ad_height = 280;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
We do not know who to credit for this solution. Several years ago we read countless tutorials and blog posts to finally find a solution that worked. Thanks to whoever you are. We pass this along in the hopes it will help someone else.