The other day I showed you my latest Adsense heat map that I have been working on for 3+ years. Mind you, that’s the only way I can give back to the community of bloggers. It’s not going to help me in the least bit because I will have more competition but I feel that it’s important to give back. Karma I call it.
Anyways, here’s how to insert ads after 1-3 sentences after your content. (Or you can change the $tcount>=1 values to something like $tcount>=3 if you want to show ads after more sentences.)
You can even show additional ads at the bottom of your content if your blog post is a long blog post versus short.
Here’s the code that will let you insert ads at different places in your content.
You need to replace in your single.php file (usually) with the following code:
The above code will print your first Adsense block after the first HTML tag p, which is usually a paragraph block or 1-3 sentences.
There’s also an option to print a second Adsense block after 4 ps for longer blog posts. This ad block won’t show unless your blog post is super long. I don’t really use the second Adsense block much. You can also change the $tcount>=4 to something like $count>=2 if you want your second Adsense block to show after the 2nd
block.
There’s also many ways to customize this code such as detecting images. For example, I used additional code to detect whether there’s an image in the very beginning of the post. If that’s the case, I will want to show the ads under the image because I think it looks better as far as web design/usability goes. I can have that code up too if more of you guys want it.
Here’s some additional div tips for styling your Adsense ads.
If you want to wrap to the right for 336×280 ads:
Replace this line with Adsense code here
If you want to wrap to the left for 336×280 ads:
Replace this line with Adsense code here
If you want to just display ads without wrap, with Adsense left aligned:
Replace this line with Adsense code here
If you want to just display ads without wrap, with Adsense center aligned:
Replace this line with Adsense code here
In general, I find that wrapping your Adsense around text can be good for CTR plus look great with your overall site design.
At other times, I find that Adsense aligned-left with no text wrapping (with white space on the right) gets a lot better CTR.
Just test the different locations to see what works best for your niche.
Instead of putting the ad after the content, it’s simply common sense they will perform better if you put it within the context of your content and higher up on your blog post.
The amount of CTR increase skyrockets plus why not?
Of course, just make sure the overall site design and user experience are still maintained, no one wants to read ad-plastered blogs, even though I am on the very edge.
Enjoy and don’t forget to share the code with other WordPress bloggers out there!



Pingback: Adsense CPC Optimized Placement Heat Map!
Thanks Max, this is really good stuff!
Hey sure, I am happy if it helps someone!
Hello, code is beautiful and it works but in a real environment, code breaks the html content. I see that this code delete the
tag and your paragraph will be without an end, this means pages aren’t anymore w3c ok, although they were before. Do you take a look at this, if possibile ? By the way thanks for sharing this really bautiful idea.Previous comment was broken, i was speaking about the end of the p tag.
Problem solved, i did some testing and, adding 2 echo do the trick. You find the new code at:
http://pastebin.com/KfsQA1ig
But we still have a (little) problem. w3c markup validation is ok but next-page wp tag is broken with this solution
Great thanks for the valid code!
thanks for the tutorial. i will try it now.
note, this code break html tag after all content, there are without start
Thanks for the tutorial, I am going to try it out now. Great Advice : )
Thanks max and Matteo too
. I am not a programmer and was trying to insert ads with in the contents. You have solved my problem.
Thanks again.
Works for me. You change that word “sentences” to paragraph though. When you change the counter number, it puts the ad after the relative paragraph, not after the number of sentences. Nonetheless a very good tutorial.
Here it is in action on my site. http://www.motorthusiast.com/420/estimated-12-hour-traffic-commute-into-and-out-of-texas-f1-track-on-race-day/
I want to show only one ad bloc in the middle of the post after one or two paragraph. Could you give a shorter code? Thanks
Pingback: How to Insert Ads in the Middle of Your Content! « World Web Corner.com
Nice tip. Earlier I was using WhyDoWork Adsense plugin to do this, but this tutorial will surely minimize the load on database and make the page load more faster.