Title: .php file include in custom fields
Last modified: August 20, 2016

---

# .php file include in custom fields

 *  [Martin](https://wordpress.org/support/users/mcundric/)
 * (@mcundric)
 * [15 years ago](https://wordpress.org/support/topic/php-file-include-in-custom-fields/)
 * Hi,
 * how can i include .php file in to custom fields?
 * My value is `<?php include(TEMPLATEPATH . '/inc/sl/page_poster/index_page_poster.
   php'); ?>`
 * In single.php i have this code: `<?php $values = get_post_custom_values('Page
   poster'); echo $values[0]; ?>`
 * Thanx for help.
 * Martin

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

 *  [s_ha_dum](https://wordpress.org/support/users/apljdi/)
 * (@apljdi)
 * [15 years ago](https://wordpress.org/support/topic/php-file-include-in-custom-fields/#post-2109564)
 * Does your code give you the right string? It isn’t mangled? If it is a good string,
   you might be able to use `eval` to include the file.
 * If you don’t mind my asking, why do you need to include this via a custom field
   instead of writing it into single.php, perhaps wrapped in a switch?
 *  Thread Starter [Martin](https://wordpress.org/support/users/mcundric/)
 * (@mcundric)
 * [15 years ago](https://wordpress.org/support/topic/php-file-include-in-custom-fields/#post-2109603)
 * If I typed in the box value just normal text, then the text is displayed correctly
   at the desired location.
 * If I include php code, then I see nothing.
 * Hmm … How do I use eval? I am a beginner in php.
 * Custom fields: I want to use it because I do not want to use the post template
   files as templet_single_home.php, template_single_products.php. In such a case
   I would have to create too many template files.
 * Thanx for your time!
 *  [s_ha_dum](https://wordpress.org/support/users/apljdi/)
 * (@apljdi)
 * [15 years ago](https://wordpress.org/support/topic/php-file-include-in-custom-fields/#post-2109629)
 * But you could include a keyword in your custom field and a switch in a single
   template.
 *     ```
       $values = get_post_custom_values('Page poster');
       switch($values) {
           case 'home' :
                include(TEMPLATEPATH.'/home_include.php');
                break;
           case 'products' :
                include(TEMPLATEPATH.'/products_include.php');
                break;
       }
       ```
   
 * Its going to be easier to write and easier to maintain. Besides, `eval()` is 
   a dangerous thing. You have to be very careful with it.

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

The topic ‘.php file include in custom fields’ is closed to new replies.

## Tags

 * [custom fields](https://wordpress.org/support/topic-tag/custom-fields/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 3 replies
 * 2 participants
 * Last reply from: [s_ha_dum](https://wordpress.org/support/users/apljdi/)
 * Last activity: [15 years ago](https://wordpress.org/support/topic/php-file-include-in-custom-fields/#post-2109629)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
