Embed Google Ad in First WordPress Post


The leading SEO (Search Engine Optimization) sites will tell you that placing an ad after the first post in your blog’s home page is particularly effective.  This is because the ad is essentially embedded in the blog content, hence your readers are less likely to develop “ad blindness” and skip over the ad as usual.  There are some WordPress plugins that will help you do this, but sometimes you need to edit the PHP code directly.

To place an ad after the first post in your WordPress blog main page:

  1. Open the WordPress admin control panel and navigate to:
    Presentation > Theme Editor
     
  2. Select the Main Index Template from the list of templates on the right.
     
  3. In the Main Index Template, find the line that starts with:
    <?php if (have_posts())
     
  4. Add the following line above it:
    <?php $count = 1; ?>
     
  5. Next, find the line that starts with:
    <?php the_content
     
  6. After the closing tag ?> for that section (it may wrap to multiple lines), add the following code:
    <?php if ($count == 1) : ?>
    – Insert your Google AdSense code here –
    <?php endif; $count++; ?> 
     
  7. Click Update File.

This places the ad within the first post.  If instead you want the ad to appear between the first and second post, add the code from step 6 after the closing </div> tag for the “entry” div that contains the line <?php the_content.

This article was published with permission from DevTopics.

Recent Entries

Leave a Reply