Title: Exclude code from certain pages?
Last modified: August 19, 2016

---

# Exclude code from certain pages?

 *  [byronb](https://wordpress.org/support/users/byronb/)
 * (@byronb)
 * [17 years, 11 months ago](https://wordpress.org/support/topic/exclude-code-from-certain-pages/)
 * Hello there, I have created an opt in form called optin.php. I want to display
   it only on my home page (static page). I created optin.php and include the code
   in my page.php (<?php include(TEMPLATEPATH . ‘/optin.php’); ?>). I only want 
   it to appear on my homepage (a specific page set to my home page), how do I stop
   it from appearing on all my other pages?
 * Regards,
    Byron

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

 *  [adamrice](https://wordpress.org/support/users/adamrice/)
 * (@adamrice)
 * [17 years, 11 months ago](https://wordpress.org/support/topic/exclude-code-from-certain-pages/#post-799054)
 * There’s more than one way to do this. You could create a specific “home.php” 
   template and only invoke that include on that file. Or you could use [conditional tags](http://codex.wordpress.org/Conditional_Tags)
   with something like this:
 *     ```
       <?php
       if is_page('home') {
       include(TEMPLATEPATH . '/optin.php');
       }
       ?>
       ```
   
 * (this assumes the page name is actually “home”)
 *  Thread Starter [byronb](https://wordpress.org/support/users/byronb/)
 * (@byronb)
 * [17 years, 11 months ago](https://wordpress.org/support/topic/exclude-code-from-certain-pages/#post-799300)
 * Thanks mate, I will try your suggestion.
 *  Thread Starter [byronb](https://wordpress.org/support/users/byronb/)
 * (@byronb)
 * [17 years, 11 months ago](https://wordpress.org/support/topic/exclude-code-from-certain-pages/#post-799336)
 * Sorry mate, I have tried different conditional statements but doesnt seem to 
   work. You said “(this assumes the page name is actually “home”) “, how do I find
   out the name of the page?
 * I added the opt in code to my page.php, is this correct?
 *  Moderator [Samuel Wood (Otto)](https://wordpress.org/support/users/otto42/)
 * (@otto42)
 * WordPress.org Admin
 * [17 years, 11 months ago](https://wordpress.org/support/topic/exclude-code-from-certain-pages/#post-799342)
 * Try `if (is_page('home'))` instead.
 * And “home” is the Page’s slug. It’s the bit that’s part of the Page’s URL. Like
   [http://example.com/blog/page-slug](http://example.com/blog/page-slug).

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

The topic ‘Exclude code from certain pages?’ is closed to new replies.

 * 4 replies
 * 3 participants
 * Last reply from: [Samuel Wood (Otto)](https://wordpress.org/support/users/otto42/)
 * Last activity: [17 years, 11 months ago](https://wordpress.org/support/topic/exclude-code-from-certain-pages/#post-799342)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
