AdSense Between WordPress Post

Posted on October 2006 at about 10:50 PM by hwa

Few days ago a friend of mine asked me how to insert Google AdSense in between posts in the main page, too bad that she is using Blogger and i’m not familiar with it.

Anyway this is how i do it in WordPress, it’s very easy actually, all you have to do is to insert the following code into The Loop:

  1. < ?php
  2. $gcount++; // google post counter
  4. if ($gadv < 3) { // how many ads to display?
  5.   if ($gcount%2 == 0) { // display ad after how many post?
  6.     $gadv++; // count number of adv
  7.     print 'Your Google AdSense Code Here';
  8.   }
  9. }
  10. ?>

Don’t forget to insert your own Google AdSense code, and you can put the above code anywhere in your “single.php” as long as it’s in between the line:

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


  1. < ?php endwhile; ?>

Which is The Loop that i mentioned earlier.

You may want to change the parameter to suit your need, there are only two parameters you can set, first one is:

For the total number of AdSense display in your home page, remember that Google only allow a maximum number of three AdSense displayed in the same page.

The second parameter would be:

  1. $gcount

This one is to set your AdSense to display after the specific amount of post, the default setting is to display AdSense every two post.

Leave a Reply

You must be logged in to post a comment.