How To Display Adsense On First Post Within IN Loop Of WordPress

Posted by


Many wordpress users wants to display Adsense on first post within the Loop. We can use this code to accomplish the requirement by editing index.php file of the theme. Find this code:

<?php if(have_posts()) : ?>

Just Above that insert this code:

<?php $i = 1; ?>
<?php if(have_posts()) : ?>

Now, find this code:

<?php endwhile; ?>

Add this code above it:

<?php $i++; ?>
<?php endwhile; ?>

Finaly, insert Adsense code where exactly like it to display within the Loop and place it between a conditional tag like this:

<?php if ($i == 1) { ?>
<?php } ?>

That’s it!


Shane G.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.