How to: Insert AdSense Ad After First Post on Homepage in WordPress?

Recently, one of our faithful reader were looking to add an AdSense ad unit after first post on homepage of his/her blog. Then I decided to write an article about inserting AdSense Ad after first post on homepage in WordPress. Yeah, this really make sense.

Insert AdSense Ad After First Post on Homepage in WordPress

I’m don’t want to go in further details about this code below but to put AdSense ad after first post on homepage just add the AdSense ad code in the following code snippet.

Add the following code in your theme’s index.php file, instead of your current WP loop. Don’t forget to add your AdSense code mentioned in the snippet below:

<?php if (have_posts()) : ?>
<?php $adcounter = 0; ?>
<?php while (have_posts()) : the_post(); ?>
<?php if ($count == 1) : ?>
          //Paste your Adsense code here
          <?php the_excerpt(); ?>
<?php else : ?>
          <?php the_excerpt(); ?>
<?php endif; ?>
<?php $adcounter++; ?>
<?php endwhile; ?>
<?php endif; ?>

Or to get rid of coding that actually irritate 🙁 .. You can Google Publisher Plugin (beta) to add Google AdSense without having to locate any code neither PHP code nor JavaScript code.

Comment below if you have any problems.

Related  How to Backup All WordPress Files and Database with Backup to pCloud

4 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *