There have been a few tutorials out there for inserting Google Adsense between posts, but a lot of them no longer work. Users have a lot of choices in Adsense plugins to insert their code within posts, sidebars, or main banner images.
However, inserting between posts, say the 4th and 5th post is not as easy and there are no plugins available. I have had clients who have asked this to be done, so here is a nifty little code snippet to add Adsense to your theme.
1. Open your index.php. Find the place in your WordPress loop after the_content or the_excerpt (depending on how your theme is coded) and before the PHP endwhile function.
2. Copy the following code
<?php if (++$PostCount == 4) {?> <!-- Insert Adsense Code Here --> <?php } ?> <?php $postcount++; ?>
3. Insert your Adsense code in place to the line asking you to add you adsense code.
Simple, huh?
Well, somewhat. You can adjust the 4 in the code snippet to another number if you wish. Also, if you need to tweak the position of your Adsense, you can insert HTML code. The code uses the WordPress post count to count the posts and insert the code where you want it to be.
Please make sure when using the code to take in consideration Google’s policy on inserting their service into your site.
Marios Alexandrou says
Check out the Ad Injection plugin. It gives you a bunch of options for inserting ads in the body content including after certain number of characters or paragraphs. You can also have it change the insertion point randomly. It’s pretty handy for testing out different insertion points without the need to modify theme files.
Anonymous says
Ok, i wanna try it to my blog, i hope i can get more income from Google Adsense…
thanks for tutorial..
marquita herald says
Great tip – you have a very attractive site!
Anok says
ya, putting adsense just below title has a good CTR 🙂
but how do we add adsense just after the 1st paragraph of every post?
Nile says
In blogspot, I am not too sure. In a self-hosted WordPress installation, there are plugins that you can specify where you want an ad to show up in an individual post.
James Hussey says
Great idea! Actually could you just use any banner besides AdSense? I don’t use AdSense myself, I prefer affiliate marketing.
I may use this on my other blogs – right now I have the Flexsqueeze theme so it’s all ready to rock with ads as it is, but I still like the simplicity of your solution here.
I DO have lots to learn about coding, that’s for sure…
Nile says
Yes, you should be able to put other banners too, whether your own in-house banner ads, or other systems.
Raj says
I guess this applies to the homepage. I have seen Blogger blogs that have done this, but I must say it was not a pretty sight! I guess it could be useful on the category pages, etc.
Herbert says
Wow!! This is what I need.. I have been looking for this one over and over again but can’t find any.. Thanks a lot Niles 😀 This makes my day complete
Herbert says
I will be back to confirm if everything works well 🙂
Nile says
It should, I am using it here. 🙂
Herbert says
Hi Niles, 🙁 sad to say it didnt, I cant find that code in index.php but instead on the on the single.php file. I have inserted it but still it didnt work.. I will give it a try again within the week maybe I placed it incorrectly
Nile says
You should be putting it into the index.php or home.php, not the single.php theme file.
ioana moise says
Amazing trick for putting adsense in wordpress i will also use on my wordpress
David says
Thanks. Having ads between posts improves chances of getting clicks!
Beth Hewitt says
Hey Nile,
It’s a pleasure to finally find you 🙂
This is invaluable information. I look forwarded to reading some of more of your posts.
To Your Success,
Beth 🙂
Kevin Schmidt says
awesome trick!
Thanks for sharing that 🙂
Also, I really like the look of your site… very cool!
-Kevin
saba says
Thank you, I am trying to help my sister fix up her blog, and been looking for this code for a while. will give it a go.
Cheers
Saba
Nick says
I have never thought about having Adsense ads between post. Time to test! I wonder what the click through rate will be like. Hopefully, a few percentages higher.
Richard says
This a very informative article to read. Providing us useful tips and refreshing information is a big help to us . I will definitely try this on my blog. And i will follow all the instruction that you have mentioned in this article. Thanks!
David Cornick says
So this is how to do it! So easy and it works.I have been trying for ages with plugin’s to insert Adsens ads between my earlier posts Thankyou
Erica says
Great tutorial! Thanks for sharing this and let me try it on my site as well!
Michael says
Hi Nile,
Brilliant trick! I’m always discovering cool little tricks to use within word press. This only adds to that long list.
Thanks again! 🙂
Michael
kayus says
Gee! thnaks for giving this code here.i would copy and past into my theme.but the way to go about this in the theme is somewhat confusing to me.
Anyway it is useful.
Nile says
This is a WordPress tutorial. It will not work in Blogger.
Mark says
Informative post…With out using any plugins it would be great
Alex says
Oh I did this so many times in my blog post and sometimes it doesn’t work well, but it helps you get traffic much….
Katie Woodard says
I have a suggestion as well. Couldn’t you just put an ad at the end of every fourth or fifth ad to acomplish the same thing.
Anonymous says
is this how i would start to make money off my blog? Currently I blog because i enjoy talking about certain subjects. Are you saying that if I followed your steps above that i could generate revenue from my blog? great!
matt says
Before I’m using adsense optimizer plugin but I remove it on my blog. With that plugin I can easily insert advertisement in between post but in my case It doesn’t have that much effect or low conversion rate. But that is only in my case I don’t know with the others who have tried it.
Ankit says
Nice post, helped me a lot to place adsense on my blog. I have one question that how can I increase my CPC in adsense, coz as far as my ad placements are concerned my CTR goes to ~4-1% but my CPC is quiet low.
Any tips to improve it??
Itender Rawat says
Thanks Admin. I was looking for this from 2 days. Its a real helpful for me.
Dipendra says
This is the best placement I earn from Adsense.
Schalk says
Hi
Osim post, simple and exactly what i was looking for, thanx!
But now I need to take it one step further, I also want to add some adsense code after post number 8.
I thought I can just duplicated the code, replacing the 4 with an 8, but no luck.
Thanx
Krypto Mehedi says
Hello Nile, I am not expert at coding. So, i just use some plugin that integrates adsense code to my post,title and others place.