Blogger: Display Adsense Ads Within Posts at any Location

Adsense is one of the main sources of income for many bloggers. Almost all bloggers are using Adsense or had used Adsense on their blogs. While using Adsense one must focus on properly integrating ads with your content to get more clicks.

Last night i was working with my design and finding a way to place ads at relevant positions within my posts. Doing something new in Blogger is very difficult, but after sometime i found a to accomplish it.

If you want to place ads within your blogger post at any arbitrary positions, then follow the steps below.

Add Adsense ads Anywhere in a Blogger Post

1. First, generate parsed code for your adsense code because we cannot put adsense code directly in the xml.

2. Now open Layout>Edit HTML>Expand Editor and search for <data:post.body/> and replace it with the code given below.

<div expr:id='"aim1" + data:post.id'></div>
<div style="clear:both; margin:10px 0">
<!-- Your AdSense code here -->
</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>

3. And finally, replace <!-- Your AdSense code here --> with the parsed Adsense code that you had generated.

In order to display adsense ad within your post add the comment <!-- adsense --> at any point where you want your ad to be displayed.

NOTE You can edit the styling of the ad to be displayed by properly modifying the style tag of div just before the point you added your adsense code in the script above.

Leave a Reply

Search

Popular Posts