Have you ever wondered how to show Google ads on your WordPress blog’s home page, but only after the very first article? Well, here is how you do it. And don’t worry, it’s quite simple, and you can’t permanently damage anything by giving it a try. ANYONE can do this!

  1. In the PRESENTATION menu, under THEMES EDITOR, find the theme file called “Main Index Template” (index.php).
  2. FIRST: Copy and paste everything you see here into a blank text file and save it. This way if you screw something up you can revert back to the original without hurting anything.
  3. Find a line of code that looks much like the following: <?php the_content('Read the rest of this entry »'); ?>
  4. Immediately after that, paste the following: <?php if ($count == 0) : ?> ENTER YOUR AD CODE HERE <?php endif; $count++; ?>
  5. Save the document and refresh your page. You should see the ad ONLY after the first article on the homepage.


So as an example, here is what the code might look like when installed (the red part is the new part):

<div class=”Post”>
      <div class=”PostHead”>
           <h1 class=”title”><?php the_title(); ?></h1>
           <p class=”PostInfo”>Posted on <?php the_time(’M d, Y - g:ia’); ?> <?php comment_time() ?> by <?php the_author() ?> in <?php the_category(’, ‘) ?></p>
      </div>
      <div class=”PostContent”>
           <?php the_content(’Read the rest of this entry »’); ?>
      </div>
</div>
<?php if ($count == 0) : ?>
<div class=”frontpage-google-ad” style=”border: dashed 1px black; padding: 10px” align=”center”>
      <script type=”text/javascript”><!–
      google_ad_client = “pub-0617773482327857″;
      google_ad_width = 468;
      google_ad_height = 60;
      google_ad_format = “468×60_as”;
      google_ad_type = “text_image”;
      //–>
      </script>
      <script type=”text/javascript” src=”http://pagead2.googlesyndication.com/pagead/show_ads.js”></script>
</div>
<?php endif; $count++; ?>

If it doesn’t show up in the right place, just try moving it around a bit and use a little trial and error. Also, remember to disable WP-Cache while you are testing the changes. If your pages are cached you won’t see the changes and it might throw you off a bit. You can enable it after you are satisfied.

Tags: , , ,

Related Articles