Title: Includes and Conditional Statements
Last modified: August 18, 2016

---

# Includes and Conditional Statements

 *  Resolved [eldeuce](https://wordpress.org/support/users/eldeuce/)
 * (@eldeuce)
 * [18 years, 8 months ago](https://wordpress.org/support/topic/includes-and-conditional-statements/)
 * I searched for this, because it’s hard to believe I am the first to attempt this,
   so i am sure it has been answered before, I’m just familiar enough with PHP and
   WordPress lingo to find it.
 * I want a contact form to be php included into a page
 *     ```
       <?php include ("includes/form.php"); ?>
       ```
   
 * was what i was using before I moved over to WP.
    Now WP has the tag
 *     ```
       <?php bloginfo('template_directory'); ?>
       ```
   
 * where it will automatically grab the directory for me
 * Also, I am using the conditional statement so the form only shows up on one page.
 * So I am trying to figure out how to get
 *     ```
       <?php
       if (is_page('3')) {
             <?php include ("bloginfo('template_directory')/includes/form.php"); ?>
           }
       ?>
       ```
   
 * all that to work.
    obviously this code does not work, but does anyone have any
   ideas of what might work?

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

 *  Moderator [Samuel Wood (Otto)](https://wordpress.org/support/users/otto42/)
 * (@otto42)
 * WordPress.org Admin
 * [18 years, 8 months ago](https://wordpress.org/support/topic/includes-and-conditional-statements/#post-622694)
 * Try this:
 *     ```
       <?php
       if (is_page('3')) {
             <?php include (bloginfo('template_directory').'/includes/form.php'); ?>
           }
       ?>
       ```
   
 *  Thread Starter [eldeuce](https://wordpress.org/support/users/eldeuce/)
 * (@eldeuce)
 * [18 years, 8 months ago](https://wordpress.org/support/topic/includes-and-conditional-statements/#post-622695)
 * Your code leaves me with
 *     ```
       Parse error: parse error, unexpected '<' in /homepages/6/d214241798/htdocs/3dss/wp-content/themes/3dss/index.php on line 17
       ```
   
 * if I change it to
 *     ```
       if (is_page('3')) {
             include (bloginfo('template_directory').'/mail.php');
           }
       ```
   
 * then at least the site shows up but I get
 *     ```
       Warning: main(/mail.php) [function.main]: failed to open stream: No such file or directory in /homepages/6/d214241798/htdocs/3dss/wp-content/themes/3dss/index.php on line 17
   
       Warning: main() [function.include]: Failed opening '/mail.php' for inclusion (include_path='.:/usr/local/lib/php') in /homepages/6/d214241798/htdocs/3dss/wp-content/themes/3dss/index.php on line 17
       ```
   
 *  Moderator [Samuel Wood (Otto)](https://wordpress.org/support/users/otto42/)
 * (@otto42)
 * WordPress.org Admin
 * [18 years, 8 months ago](https://wordpress.org/support/topic/includes-and-conditional-statements/#post-622697)
 * I was just editing the code you used, I didn’t notice your incorrect php tags.
 * And why did you change it to “mail.php”? Why not tell me what you’re actually
   trying to do here. Where are your files actually located?
 *  Thread Starter [eldeuce](https://wordpress.org/support/users/eldeuce/)
 * (@eldeuce)
 * [18 years, 8 months ago](https://wordpress.org/support/topic/includes-and-conditional-statements/#post-622698)
 * I use both form.php and mail.php – this one just happened to be named mail.php,
   sorry.
 * i took it out of the includes folder, in hopes that it might help… no such luck.
 * I verified that the mail.php is uploaded, so that shouldn’t be the issue. Why
   else would it fail to open?
 *  Moderator [Samuel Wood (Otto)](https://wordpress.org/support/users/otto42/)
 * (@otto42)
 * WordPress.org Admin
 * [18 years, 8 months ago](https://wordpress.org/support/topic/includes-and-conditional-statements/#post-622699)
 * If these files are in your template directory, then the correct code should be
   this:
 *     ```
       if (is_page('3')) {
             include (get_template_directory().'/mail.php');
           }
       ```
   
 * The bloginfo template function returns the URI, not the actual path.
 *  Thread Starter [eldeuce](https://wordpress.org/support/users/eldeuce/)
 * (@eldeuce)
 * [18 years, 8 months ago](https://wordpress.org/support/topic/includes-and-conditional-statements/#post-622700)
 * the get_template_directory() was ace!
 * thanks for the help, again!! 😀

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

The topic ‘Includes and Conditional Statements’ is closed to new replies.

## Tags

 * [template directory](https://wordpress.org/support/topic-tag/template-directory/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 6 replies
 * 2 participants
 * Last reply from: [eldeuce](https://wordpress.org/support/users/eldeuce/)
 * Last activity: [18 years, 8 months ago](https://wordpress.org/support/topic/includes-and-conditional-statements/#post-622700)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
