Have you ever tried to insert advertisements (or any bit of code really) into the WordPress post loop, then found that it will insert the banner after each post? It really depends on what you are going for, but this usually will not be an ideal solution to placing advertisements between posts on your homepage. If you’d like to place something only after the first post in the WordPress post loop, here is a quick hack you can do to tell WordPress to only display it after the first post.
Simply go to your themes homepage and look for the following code:
<?php endwhile; ?>
Immediately before this code, place the following code:
<?php if(!$show_ads){ ?>
Insert Code Here
<?php $show_ads = 1; } ?>
Obviously you’ll want to replace Insert Code Here with your code. Told you it was easy!
















I need to put adverts into my post, not just in widget and the sidebar. I’ve bookmarked your page to remind me of what to do. Many thanks
Ian
If only everything were that simple
Thanks Kyle, this is simple and easy.
Glad everyone found it both easy and useful!
hey, is there any way to put the ad after say, the 3rd post? is it as simple as changing the to ???
Thanks!
HackWordpress rulezz!
On a blog of mine, i use Adsense in the main index template, and 3 occurences of the banner appear on the homepage, as this is the max allowed by Google per ad unit.
However on the 4th and remaining posts, there is an ugly space. I will try your hack and hope this helps it.
Missy.
What about simply using this code:
Your code here…
hmm… I should have known code will not be published…
your code here
What about this?
Well… that’s working great…
Sorry!
nice hacks..
keep it up.
thanks a lot for that, its such a simple snippet of code and very simple instructions
you are a living legend!
see ya
ET
http://tariksport.com/nfl-blog/
Thanks for this! Easy hack…. if you want after the 3rd article for example, change the 1 to a 3… the number represents the article # that you want to place the ad after.
Make sure to add tags before/after the ad to give it some space. You can see the end result on my blog.
Great code. Is there any way to make this only take effect after the first post on only the first page?
Never mind. I figured it out. I put ‘& !is_paged()’ in the conditional to get it on the homepage only and not its subsequent pages or ‘previous entries’.
Thanks for enlightenment!
Super! nice hacks..
keep it up.
Whoa!!
I been trying to figure this out for a while and you solve the problem with a couple of lines of code.
Well done, and thanks for the tip.
Here is another way : http://www.saijogeorge.com/2009/12/24/ads-after-the-first-post-in-wordpress-on-homepage.html
With that you can add it after nay post not just the first.
It’s cool tutorial and easy to be implemented.
Can you help me? How to add it on after first post and then add it again on 3 next post.
thanks..
Thanks! This was exacly what I needed. Simple and easy!
I try to implement this code but it appears at the bottom of the post after the last post on homepage. Hope can get it works as everyone else
The same happens with me… otherwise It works great!
Thanks!
Very nice and easy hack…
I wonder why didn’t anyone make a small plug in for this, so we don’t have to fix it any time we change template…