Skip to main content

How To Put Adsense In The Middle of Post Automatically

Many Bloggers are asking me on what code/css did I use to put ads in the middle of my posts. Well I have my post before about putting adsense ads anywhere in the posts but that is manually adding of <!-- adsense -->.  Now I will show this code that  will add the adsense ads automatically. As I research about this there are some posts about his and one is in Ajbanda article of showing ads in the middle of post, He created a code that will look for  <br/> tags on the articles, this one just simplified version of the code

How To Put Adsense In The Middle of Post Automatically

First things first: Must take backup of your template before making any change.
( Tips: Use the Asynchronous Adsense Code for Maximizing Page load)

1. Find <head> tag in your blogger template and place latest jquery just below it. Please avoid to use two jquery links, remove older one and use new version.
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js" ></script>

2. Second look for this code <data:post.body/> inside your template and replace it with the following code -
<div id="PostBody">
 <data:post.body/>
</div>

<div id="AdCode">
<div style='margin:5px 0;text-align:center;clear:both;'>
 <!-- Ad Unit Code Here -->
</div>
</div>

New Blogger template may have 2 or 3 <data:post.body/> code. You should have to identify correct one. Generally 2nd instance of <data:post.body/> is right code to replace in new blogger templates.
3. Now search for </body> tag inside your template and put following javascript before/ just above it.
<b:if cond='data:blog.pageType == &quot;item&quot;'>
<script>
 $AdCode = $("#AdCode").html();
 $("#PostBody br:lt(1)").replaceWith($AdCode);
 $("#AdCode").remove();
</script>
</b:if>

4. Save the changes in Blogger template and have fun.

You can choose your Ad location

By replacing the value br:lt(1) with br:eq(n), where n= 1, 2, 3… which is number of line breaks after which Ad will appear in your post. e.g. If you want to show Ad after 5th line break then replace br:lt(1) with br:eq(5) and you are done.

Before placing the Ad codes be sure to Parse the adsense codes. You can use my parser: HERE
As I read on the adsense policy there are no specific about this one and I think this is just placing the ads inside blog post like placing it below post title which is allowed.
You can also read their Policy. Final choice is yours, you will use it for your blog or not.

Comments

  1. Thank you very much for the tutorial helped me a lot to set up my blog

    ReplyDelete
  2. Hi Again, I used br:eq(n) and it is now showing an extra ad at the end of my posts too. Can you help figure me out why this is so?

    ReplyDelete

Post a Comment

Popular posts from this blog

How to Use Facebook, Disqus and Blogger Comment tab Together in Blogger Blogs

As writers of  blogs, we all are aware of the importance of comments. While it is true that some blogs/websites tend to disable comments entirely, those are special instances where the websites do not essentially require comments. However, in general, comments form an integral part of any blog, be it a personal one or a magazine site. After all, what good is any info unless it provokes a healthy discussion?

All blogging platforms (including WordPress) come with native support for some sort of comment mechanism which seems to suffice for most bloggers. But sometimes, users may require some dedicated or specialized comment mechanism. This is where third-party commenting systems come in handy. In this article, we will take a look at some of the major third-party commenting mechanisms

Disqus
Disqus is a mature comment management system and perhaps the most used amongst bloggers and website owners. Introduced back in 2007, it is currently serving more than 750,000 websites. According to a …

High PageRank Do-Follow Forums List (606)

Besides from getting your answers to unanswerable queries, the good thing of do-follow forums is to create a good back links through their High Page rank pages on Google, creating your pointing to your site makes your blog grows faster in ranking,

Now a days it is very hard to find do-follow link website because they are making their site as no-follow, like the wiki, it is before a do-follow site but since many SEO experts use wiki as spam they control it and made it no-follow, so now I am giving you a list of do-follow and high ranking sites that you can use to make your blog popular.

Its your tactics on how to create your links on this site, but remember not to spam cause Google might hit you. :)

Here are the list enjoy

ForumPR1http://www.addthis.com/forum92http://chronicle.com/forums/83http://forums.myspace.com/84http://forum.joomla.org85http://forums.cpanel.net86http://forum.siteground.com87http://c7y-bb.phparchitect.com88http://forum.meebo.com89http://forums.mysql.com/710http://f…

FIXED! Adsense Ads not Showing in Homepage of Blogs or Website

Problem Solved! have you experience your Adsense ads not showing on homepage? Ads are showing on other pages except for homepage, well just this week I had a hard time figuring out why my ads are not showing in homepage.

I have another blog that is using Adsense ads. After a day of fixing almost all my template errors still the Adsense ads are not showing so I tried to search for it on internet.

Some forums will tell you that it is about updating your privacy policy pages, well I did that also but there's no effect.

The solution is very simple just navigate to blogger setting or wordpress seo settings. I'm focusing on blogger since my blog is in blogger platform.




Go to Blogger settings ->> Search Preferences->> Enable search description. Click yes then put your sites description and save. That's it! reload and see the magic :D