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

No votes yet.
Please wait...

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.

Similar Posts

4 Comments

  1. Hello Haroon,
    It’s so easy code. I was searching for this code about 15 minutes but here I found my solution. thansk Haroon

    No votes yet.
    Please wait...
    1. No problem if this article helped.

      No votes yet.
      Please wait...
  2. Really you solved my issue. Thank you.

    No votes yet.
    Please wait...
    1. Yeah it does, thanks for stopping by 🙂

      No votes yet.
      Please wait...

Leave a Reply

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