Google limits the number of ads that you can place in your blog per page. When you place the adsense code by modifying index.php so that the ad appears below a post, the ad is going to appear beneath all the posts on your blog’s homepage. This is not what we want.
For the ad to only appear under the first post and nowhere else,
The Quick Way
Edit index.php and place the following code wherever you want the ad to appear:
<?php if ($wp_query->current_post < 1) {
adsense_deluxe_ads('above_posts');
} ?>
Replace adsense_deluxe_ads(’above_posts’); with your adsense code. If you want the ad to appear below the post, you would paste the above before <?php endwhile; ?>
We’ve similarly placed 3 link units at the top of first three posts on our home page using this code:
<?php
if ($wp_query->current_post < 3)
{
include('adsense_indexpage_firstthreeposts_linkunit.php');
}
?>
The Long Way (We are no longer using this method, now that we’ve discovered the quick way)
- Open your theme’s index.php, and find this line:
- Immediately above that, paste this:
- Staying in index.php, scroll down to this part:
- Above <?php endwhile; ?>, paste this:
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php $postnum = 1; $showadsense1 = 1; ?>
<p class="postmetadata">Posted in <?php the_category(', ') ?> | <?php edit_post_link('Edit', '', ' | '); ?> <?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?></p>
</div>
<?php endwhile; ?>
<?php if ($postnum == $showadsense1) {
echo '
Your adsense code goes here
';
} ?>
<?php $postnum++; ?>
Paste the adsense code where it says Your adsense code goes here.
If you are using Adsense-Deluxe plugin, you can replace
echo ' Your adsense code goes here '
with the plugin provided code like
<?php adsense_deluxe_ads('adsense_below_first_post'); ?>
This can similarly be extended to archives and search page by editing archive.php and search.php respectively.
We hope you found this how-to helpful. Please social bookmark this tutorial and help us and others. Thanks in advance.

This post has no comments yet. Why not kick start the discussion?