Show ads after first post in WordPress

Posted in WordPress · December 28th, 2010 by Kazim · Comments (3)

As you see Homepage of my website. I’ve a banner advertise after first post. It doesn’t mean which ever post you’ve this trick let you allow to add it after your first post. Sometime you want to insert ad after first post and you do it by inserting your ad code in WordPress Loop. Next you found is that it is showing after each post. Obviously we can’t afford to have that much ads on Homepage, neither Google Adsense as per their TOS allow us to do it. As by alternative to be preferred is banner ad placement after first post on your blog homepage. Either this trick also work if you want to place something else you would like to after first post. Below is quick tip to show anything after first post in WordPress.

  • Go to Appearance > Editor
  • Look for the file, Index.php or whatever hold your homepage
  • Look for following code in the file
<?php endwhile; ?>
  • BEFORE this code add the following code
<?php if(!$show_ads){ ?>
Your Ad Code Here
<?php $show_ads = 1; } ?>

Simply you will have to replace Your Ad Code Here with your Adsense Code or whatever you’d like to place after first post.

Credits shall be to thee: WpHacks

Tags: , , , , , , , , , , , , ,

Related Posts



Leave a Reply