Google Adsense logoFor some time now, surfing around the internet I’ve noticed, and you may have noticed as well, that a lot websites at the homepage have ads between posts from Google Adsense and other advertising companies. One of the main reasons is that one of the most effective places to insert ads is right-after the first post and it could potentially increase revenue. But you should notice that there may be a difference of CTR (Click Through Rate) when you compare to ads inserted before the first post, but it is like, a mentioned before, more effective and also looks cleaner.

Alright! Now to the good stuff, in this Set WordPress tutorial you are going to learn how insert ads between post in your WordPress homepage:

1.  Connect to your WordPress site via FTP or go to your WordPress Dashboard, in the menu go to Appearance and choose Editor. Now locate and open the index.php or the loop.php (this will depend on your theme template) file and look for a line of code similar to this:

<?php while (have_posts()) : the_post(); ?>

2.  Once you’ve found it, you need to insert the following line above it:

<?php $count = 1; ?>

3.  Next find the following line that looks like this:

<?php endwhile; ?>

4. Once you’ve found it, you need to insert the following lines of code with the Google Adsense code or the code from the advertising company you are using above it:

<?php if ($count == 1) : ?>
<?php endif; $count++; ?>

Now if you see in the last piece of code, the first line contain this part: $count ==1, the number 1 indicates the position where the ads will be inserted, in this case will be after the first post. If you want to insert ads after the third, fourth post… You are going to have to increase this number to 3 or 4 and so on.


What about adding more than one ad unit between posts in the homepage!

Well if this is your case, you need to follow all the steps above and insert the following lines of code right-after php endif; $count++; ?>:

<?php if ($count == 3) : ?>
<?php endif; $count++; ?>

As you can see the code is just part of the first ad, only this time we increased the number or the position of where the next ad will be inserted — Play with the numbers until you get the results you want –.

Remember to save the index.php or the loop.php file, and now your WordPress site at the homepage is going to display an ads between the published posts, depending in your configuration. Happy revenue!

Tip: You can use this same method to insert other things, such as  images, customs ads, etc. by just replacing the Google Adsense code with what you want.

If this Set WordPress tutorial was useful to you, please share it in Twitter, Facebook and Google +1.