fbpx
4

Adsense Tips: How to place your ad between your blog posts in WordPress

Last modified on 12th March, 2006

OK, time for another Adsense Tips.

I had been looking for a way to do this or a plugin that can help me achieve the same effect. I’d probably end up doing it myself if I couldn’t find anybody who has posted about this.

Anyway, Aaron Brazell, the new ProBlogger columnist posted this tip recently.

If you look at Sabahan.com main page, you’ll notice that I’ve placed the Adsense rectangle ad after the 3rd, 6th, and 9th posts. BTW, I might change this setup in the future.

The way I do this is by editing the following block of code in my index.php file.

 

Yours may be a little different from mine but it should resemble either this:

 

<?php if ($posts) : foreach ($posts as $post) : start_wp(); ?>

Some code here…

<?php endforeach; else: ?>

 

Or this

 

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

Some code here…

<?php endwhile; ?>

 

This is where wordpress loop through and display your post one by one as long as there are posts to display.   What I’ve done is to add a counter to count if a particular post is the 3rd, 6th, 9th, 12th and so on. If that condition is true, then my Adsense code will be placed at the end of that post. So, for the first code snippet example above, add   <?php $counter = 0; ?>   before

 

<?php if ($posts) : foreach ($posts as $post) : start_wp(); ?>

 

Then add the following code to display your Adsense code after the 3rd , 6th , 9th etc. posts only.  

<?php if(++$counter % 3 == 0) { Echo “Your Adsense code here”; } ?>  

 

It must be added before the end of this code: 

 

<?php endforeach; else: ?>

 

Your final code should look like this. For the first code snippet    

 

<?php $counter = 0; ?>

<?php if ($posts) : foreach ($posts as $post) : start_wp(); ?>

Some code here…

<?php if(++$counter % 3 == 0) { Echo “Your Adsense code here”; } ?>

<?php endforeach; else: ?>

 

And if your index.php code resembles the second code snippet, your final code should look like this:

 

<?php $counter = 0; ?>

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

Some code here…

<?php if(++$counter % 3 == 0) { Echo “Your Adsense code here”; } ?>

<?php endwhile; ?>

 

To change the ad intervals between your posts, just change the number ‘3′ above to a different number.   If you want to display one ad only after the 2nd , 3rd , 4th etc and not have it repeated, you can refer to the original tips at ProBlogger on how this is done.  

My advice is not to go overboard, plastering your blog with ads all over thinking to make more money at the expense of your readers’ experience. In such case, what’s more likely to happen is you’ll annoy them, and risk losing your regular or potential readers.

You can check out my earlier post for more Adsense tips for blogger.

Gaman
 

An engineer by training, Gaman has been working full-time online as an Internet marketer, a programmer and an app developer since 2001. He has been blogging at Sabahan.com since 2006 sharing his experience and teaching people how to make money online. Click here to join his private Facebook Group for bloggers.

  • […] How to: Placing Adsense Strategically Between Posts Adsense Tips: How to place your ad between your blog posts in WordPress […]

  • […] While MightyAdsense plugin insert the adsense code 1,2 or 3 times consecutively, you can have such an “interval” between them by applying tips covered by sabahan.com. In this tip, I believe that you need to edit your template, look for posts loop, make a test and display the adsense code. The test depends on how you would like the code to be positoned, such as at every odd or even number, every 2 or 4 posts etc. […]

  • Gaman says:

    I guess I was searching using different keywords. Anyway, cheers mate.

  • LcF says:

    Erm.. we have the code 1 year ago in WordPress support forum. I also published a adsense random placement code.

  • >
    Scroll Up

    Want to Create a Successful Blog & Make Money? 

    Sign Up Below... For Tips and Tools to Help You Build a Better Blog

    >> Sign Up Now and get access to:


    • chevron-circle-right
      The exact methods I use to make money
    • chevron-circle-right
      Resources to increase traffic to your blog
    • chevron-circle-right
      The latest updates from Sabahan.com
    arrow-down