Title: Code to Run Specific Ads on Specific Posts
Last modified: August 19, 2016

---

# Code to Run Specific Ads on Specific Posts

 *  Resolved [evilbeet](https://wordpress.org/support/users/evilbeet/)
 * (@evilbeet)
 * [16 years, 9 months ago](https://wordpress.org/support/topic/code-to-run-specific-ads-on-specific-posts/)
 * I’ve been asked to change the ad code that runs only on three specific posts —
   on the other posts the regular ads will run. I tried to piece together some PHP
   code for it and came up with this:
 *     ```
       <?php if( ($post->ID == 43751) || ($post->ID == 43647) || ($post->ID == 43611)) { ?> 
   
       <iframe id="Adv1" src="http://ad.doubleclick.net/adi/real.filmcom/evilbeetgossip;pageurl=/evilbeetgossip;cat=tvondvd;subcat=;contentid=;dcopt=ist;sz=728x90;ord=14456755;tile=1"
       width="728" height="90" marginwidth="0" marginheight="0" frameborder="0" scrolling="no">
       </iframe>
   
       <?php } ?> 
   
       <?php else { ?>
   
       <iframe id="Adv1" src="http://ad.doubleclick.net/adi/real.filmcom/evilbeetgossip;pageurl=/evilbeetgossip;cat=celebrities;subcat=;contentid=;dcopt=ist;sz=728x90;ord=14456755;tile=1"
       width="728" height="90" marginwidth="0" marginheight="0" frameborder="0" scrolling="no">
       </iframe>
   
       <?php } ?>
       ```
   
 * Unfortunately when I put this code in header.php the site doesn’t load. I’m sure
   there’s some parsing problem but I don’t have enough knowledge of PHP to figure
   out what it is. Help?

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

 *  [shane-g](https://wordpress.org/support/users/shane-g/)
 * (@shane-g)
 * [16 years, 9 months ago](https://wordpress.org/support/topic/code-to-run-specific-ads-on-specific-posts/#post-1194107)
 * Hi,
 * Have a check with these steps:
 * – Open index.php file of your wordpress theme.
    – Search the code:
 * <?php endwhile; ?>
 * Add this code before that:
 * <?php if(!$show_ads){ ?>
    Your Advertisement Code here…. <?php $show_ads = 1;}?
   >
 * Thanks,
 * Shane G.
 *  [iridiax](https://wordpress.org/support/users/iridiax/)
 * (@iridiax)
 * [16 years, 9 months ago](https://wordpress.org/support/topic/code-to-run-specific-ads-on-specific-posts/#post-1194128)
 * See: [http://codex.wordpress.org/Conditional_Tags#A_Single_Post_Page](http://codex.wordpress.org/Conditional_Tags#A_Single_Post_Page)
 * Try this format and make sure it’s in the `<body>` section:
 *     ```
       <?php if (is_single(array('1','2'))) { ?>
       <!-- code here -->
   
       <?php } else { ?>
       <!-- code here -->
   
       <?php } ?>
       ```
   
 *  [S.K](https://wordpress.org/support/users/kichu/)
 * (@kichu)
 * [16 years, 9 months ago](https://wordpress.org/support/topic/code-to-run-specific-ads-on-specific-posts/#post-1194139)
 * I think (if I’m not terribly wrong), your script can’t parse and return any post
   related information unless you do a query posts. Since you try to include the
   conditional in the header.php, you have run a sql query for posts to make it 
   work.
 * S.K
 *  Thread Starter [evilbeet](https://wordpress.org/support/users/evilbeet/)
 * (@evilbeet)
 * [16 years, 9 months ago](https://wordpress.org/support/topic/code-to-run-specific-ads-on-specific-posts/#post-1194148)
 * Oh, thanks, I didn’t know about this is_single() function. I used the code you
   suggested and it’s working now. Thank you SO much, I really appreciate the prompt
   responses!

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

The topic ‘Code to Run Specific Ads on Specific Posts’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 4 replies
 * 4 participants
 * Last reply from: [evilbeet](https://wordpress.org/support/users/evilbeet/)
 * Last activity: [16 years, 9 months ago](https://wordpress.org/support/topic/code-to-run-specific-ads-on-specific-posts/#post-1194148)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
