Text Link Ads
Email This Post Email This Post

How to add AdSense between WordPress posts in 10 Easy Steps

Wordpress, Blogging Tips June 23rd, 2007

    Visited 936 times, 1 so far today

I was looking long and hard for a tutorial to tell me how I go about adding Google Adsense between posts. Although I found several articles none of them really explained it clearly enough for me to understand it well enough. Anyway, luckly my husband is a programmer and he fixed my problem so now you can see on my home page and category pages how my Adsense fit nicely between my posts.

I decided to share my code with anyone who needs it so they can too place Google AdSense between WordPress posts. I will explain this in 10 easy steps, please feel free to drop any comments if you have problems or suggestions.  The following tutorial will display the Adsense after the 1st, 2nd and 10th (last) post on the home page of your site. If you want a demo of this then you can view my home page.

BEFORE WE BEGIN - Do you have the Adsense code to place on your site? If yes, proceed with tutorial, if no, then you need to

  1. Login to your WordPress administration panel
  2. Select Presentation ->Theme Editor from the navigation menutheme editor
  3. On the Theme Editor page, you will see a list of “theme files” to the right of the page. Select the “Main index template” (index.php).theme files
  4. Find the following line
    <?php while (have_posts()) : the_post(); ?>
  5. Above it add the following line
    <?php $count = 1; ?>
    Comments:-$count is the variable and you have to assign a value to that variable. In this case the value is 1.
  6. Find the line <?php endwhile; ?>
  7. Add the following code directly above it (replace AdSense Code with your code)
    <?php if ($count == 1) : ?>
    AdSense Code 1
    <?php elseif ($count == 2) : ?>
    AdSense Code 2
    <?php endif; $count++; ?>
    Comment:-We can count how many times the loop has cycled by adding the block of code above. Remember at the start we added <?php $count = 1; ?>, well above we check $count, if count is 1 we place adsense code 1, if its 2 we place adsense code 2.NOTE : To change which post your Adsense is placed under, simply change the count number, for example: $count == 2 will place the Adsense under post 2
  8. Find the line <?php endwhile; ?>
  9. Below it add the following code:
    <?php if ($count != 2 AND $count != 3 ) : ?>
    Adsense Code 3
    <?php endif;  ?>
    Comment:-The adsense will be added after the very last post on the home page because it’s been added after <?php endwhile; ?>It also tells us that if the adove 2 ads are not the last ads than add Google Adsense Code 3 at the end.
  10. Click Save, then go view your site to confirm that the Adsense has been added to the first post listing on your home page. Note - if you want the same thing to show on the category or archive pages then that’s easy. You just need to copy and paste what you ‘ve done to either your archive.php or category.php.

That’s it your done! :)

Leave a Reply


             



Resources

Categories

FREE Newsletter

Sign up TODAY and get FREE Tips every Week on Making Money on the Internet 

(required)
(required)
 

Increase your Blog Traffic


     

Auction Ads


     

Recommended Book


      

Tag Cloud

Wordpress Blog Marketing Blogging Tips Blogging Tools and Services Advertising VoIP Blogging for Money Search Engine Optimization Adsense General

Recommended Money Makers


    
      Text Link Ads
      Blog Mastermind Affiliates
      AuctionAds
      Amazon Associates

Related Articles

Recent Articles

Advertisements