How to Insert an AdSense Ad Anywhere Inside a Blog Post

It's nice to have the flexibility of inserting a Google AdSense ad anywhere inside a blog post. After the title, after the first paragraph, in the middle of the post ... anywhere at all! Before beginning, get into AdSense and create your ad.



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.




  1. 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.
  2. 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.
  3. <div class='post-body entry-content'> <data:post.body/> <div style='clear: both;'/> <!-- clear for photos floats --> </div>
  4. Place your cursor after the line <div class='post-body entry-content'> and press the Enter key 7 or 8 times.
  5. Then, delete the line <data:post.body/>
  6. 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='&quot;aim1&quot; + 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='&quot;aim2&quot; + data:post.id'>
<data:post.body/>
</div>

<script type='text/javascript'>
var obj0=document.getElementById(&quot;aim1<data:post.id/>&quot;);
var obj1=document.getElementById(&quot;aim2<data:post.id/>&quot;);
var s=obj1.innerHTML;
var r=s.search(/\x3C!-- adsense --\x3E/igm);
if(r&gt;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 &lt; - 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:
  1. Go into your Google AdSense account and and find the code for your AdSense ad. Copy the code.
  2. 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."
  3. 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.)
  4. 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":

&lt;script type=&quot;text/javascript&quot;&gt;&lt;!--
google_ad_client = &quot;pub-9999999999999999&quot;;
/* 336x280 rect, created 9/9/09 */
google_ad_slot = &quot;9999999999&quot;;
google_ad_width = 336;
google_ad_height = 280;
//--&gt;
&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot;
src=&quot;http://pagead2.googlesyndication.com/pagead/show_ads.js&quot;&gt;
&lt;/script&gt;


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.

14 comments:

  1. I appreciate such a well written post.

    ReplyDelete
  2. Thanks. Well done.

    ReplyDelete
  3. It workedddddddddddddddddddddddddddddddddddddddddddddd after 50 trials from so many searches that google started making me enter a capthca because they thought my computer was giving automated querries it finally worked thank you soooooooooooooooo much Im so grateful.

    ReplyDelete
  4. it still now working for me , the adsense ad just showing below the title only and the tag is showing like text not replaced by the ads :( could you help me please

    ReplyDelete
  5. I really want to install this on my blog but unfortunately, it doesn't work. I've done lots of tweaks on the codes but still not working. Tsk tsk. I hope somebody could help me out.

    ReplyDelete
  6. I've done a few tweaking again just now and this time, it is now working on my blog!!! THanks Patricia. :D Check out my blog.

    ReplyDelete
  7. Very useful information...Thanks for guiding.

    ReplyDelete
  8. woooohooooo. thank you so much for this. i've been searching for hours how to do this. it works perfectly.

    ReplyDelete
  9. Yes it is working again perfectly after changing my template to standard one
    thanks patricia

    ReplyDelete
  10. very guideline post,its a great educational post

    ReplyDelete
  11. By far the best tutorial on this subject. It worked perfectly. Thanks alot!

    ReplyDelete
  12. I have copied, the code and click next but nothing is matched or I can not see any thing happened. Please someone help me, please.

    ReplyDelete
  13. After several tries I finally got it to work. I can't believe it. Best write-up I found - Thanx

    ReplyDelete
  14. To those who find that this solution is not working, let us state:
    - This solution worked on the Blogger templates when the post was created a couple of years ago, and it should work on current templates. The reason we wrote this post is because none of the tutorials we found worked for us and we had to upload a fresh template several times and start from the beginning before we found a working solution. Make sure you follow our instructions to download a copy of your template before changing the code so you can start again if you make a mistake.

    - So, before deciding that this solution does not work, upload a fresh copy of your template and start again - following the instructions very carefully. Go SLOW. You must be careful; there cannot be a comma or any other character missing, extra, or in the wrong place!
    - Also, make sure you are typing <!-- adsense --> correctly in your post.

    - Some folks have told us that they got this solution to work and could place the AdSense ad wherever they wanted only after that changed their template to a newer, standard one.

    Comments closed (4/1/11)

    ReplyDelete