Title: Adding Ads To Theme??
Last modified: August 19, 2016

---

# Adding Ads To Theme??

 *  [miamistud62](https://wordpress.org/support/users/miamistud62/)
 * (@miamistud62)
 * [16 years, 2 months ago](https://wordpress.org/support/topic/adding-ads-to-theme/)
 * I’m sure that this question has been asked multiple times, so I apologize for
   repetition. I recently joined an affiliate marketing program (other than Adsense)
   and I want to put the ads on the Home Page centered under each post. Maybe, if
   possible, under the actual posts and on the side of the pages (left, right). 
   Furthermore, it would be cool if I were able to set it up so that it fluctuates
   between a few different ads so that the same one doesn’t show up each time. Is
   there a way to do this?
 * thanks a lot in advance, I appreciate it!

Viewing 4 replies - 1 through 4 (of 4 total)

 *  [MichaelH](https://wordpress.org/support/users/michaelh/)
 * (@michaelh)
 * [16 years, 2 months ago](https://wordpress.org/support/topic/adding-ads-to-theme/#post-1399257)
 * Start here;
    [http://codex.wordpress.org/User:Tomhanna/Adding_Ads_to_Wordpress](http://codex.wordpress.org/User:Tomhanna/Adding_Ads_to_Wordpress)
 *  [Snat](https://wordpress.org/support/users/snat/)
 * (@snat)
 * [16 years, 2 months ago](https://wordpress.org/support/topic/adding-ads-to-theme/#post-1399270)
 * My reply is just a guideline, so don’t expect exact copy and paste code but anyhow.
   You can do this via editing your theme files (there may be a plugin out there,
   but I haven’t seen one).
 * > ‘m sure that this question has been asked multiple times, so I apologize for
   > repetition. I recently joined an affiliate marketing program (other than Adsense)
   > and I want to put the ads on the Home Page centered under each post
 * This can be done by editing index.php and single.php in your theme folder and
   looking for the loop. You will see something like this:
 *     ```
       <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h2>
       ```
   
 * By putting your ad under that part directly, you will be able to place code that
   will be inserted after the header of each post. Example:
 *     ```
       <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h2>
       <div align="center">WordPress is so cool</div>
       ```
   
 * > Maybe, if possible, under the actual posts and on the side of the pages (left,
   > right).
 * Now, I ain’t sure what you mean by this but anyhows I will answer on how I think
   you meant. I am under the understand that you want to be able to place an ad 
   at the end of the post on both sides of the post but if you look for
 *     ```
       <?php the_content('Read the rest of this entry &raquo;'); ?>
       ```
   
 * After that you could once again place a floating DIV such as
 * <div align=”left”>WordPress is so cool</div>
    <div align=”right”>WordPress is
   so cool yet again</div>
 * That is just rough code that should get to start in those cases.
 * > Furthermore, it would be cool if I were able to set it up so that it fluctuates
   > between a few different ads so that the same one doesn’t show up each time.
   > Is there a way to do this?
 * This too is possible and below I have put an example that you can use. Now this
   ain’t the best way to do it, but it happens to be a working way you can work 
   from.
 *     ```
       <?php
       srand ((double) microtime( )*1000000);
       $random_number = rand(0,10); // 10 is the max number of ads you want
       if $random_number == "1"{ echo "Ad One"; }
       if $random_number == "2"{ echo "Two"; }
       .....
       ?>
       ```
   
 * Hopefully my reply is helpful in terms of physically coding it but chances are
   there is a plugin out there that will do it. Also, might want to look at – [http://codex.wordpress.org/User:Tomhanna/Adding_Ads_to_Wordpress](http://codex.wordpress.org/User:Tomhanna/Adding_Ads_to_Wordpress)
 *  Thread Starter [miamistud62](https://wordpress.org/support/users/miamistud62/)
 * (@miamistud62)
 * [16 years, 2 months ago](https://wordpress.org/support/topic/adding-ads-to-theme/#post-1399473)
 * Thank you both. This was a big help. Only problem I’m having is with the last
   script with the random ads. I’m not sure if the “if” statement is missing a ‘
   then’ or something but that’s not working out for me… it adds them both in simultaneously
 *  [Snat](https://wordpress.org/support/users/snat/)
 * (@snat)
 * [16 years, 2 months ago](https://wordpress.org/support/topic/adding-ads-to-theme/#post-1399503)
 * Sorry, my code is wrong was quite sleepy when I replied.
 *     ```
       <?php
       srand ((double) microtime( )*1000000);
       $random_number = rand(0,4); // 4 is the max number of ads you want
   
       if ( $random_number == "0" ) { echo "Ad 1"; }
       if ( $random_number == "1" ) { echo "Ad 2"; }
       if ( $random_number == "2" ) { echo "Ad 3"; }
       if ( $random_number == "3" ) { echo "Ad 4"; }
       if ( $random_number == "4" ) { echo "Ad 5"; }
   
       ?>
       ```
   
 * That works, I just tested it. Make sure to edit the part where ti says “Ad X”
   with the HTML you want.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Adding Ads To Theme??’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 4 replies
 * 3 participants
 * Last reply from: [Snat](https://wordpress.org/support/users/snat/)
 * Last activity: [16 years, 2 months ago](https://wordpress.org/support/topic/adding-ads-to-theme/#post-1399503)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
