Title: [Plugin: Custom Field Template] using PHP in the_content() hook
Last modified: August 19, 2016

---

# [Plugin: Custom Field Template] using PHP in the_content() hook

 *  [Mark](https://wordpress.org/support/users/codeispoetry/)
 * (@codeispoetry)
 * [16 years, 10 months ago](https://wordpress.org/support/topic/plugin-custom-field-template-using-php-in-the_content-hook/)
 * This experimental `the_content()` hook is fabulous. Saves one from adding shortcodes
   into posts. However, I’d like to use PHP code in it to set the field to not display
   when empty (using [this type of code](http://wordpress.org/support/topic/186234?replies=9#post-795116)).
 * Right now when I check ‘Use PHP’ it throws errors like `unexpected $end` and 
   so on. Playing with the PHP code doesn’t seem to solve the problem.
 * [http://wordpress.org/extend/plugins/custom-field-template/](http://wordpress.org/extend/plugins/custom-field-template/)

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

 *  [Hiroaki Miyashita](https://wordpress.org/support/users/hiroaki-miyashita/)
 * (@hiroaki-miyashita)
 * [16 years, 9 months ago](https://wordpress.org/support/topic/plugin-custom-field-template-using-php-in-the_content-hook/#post-1136817)
 * You can not separate the php codes if you have conditional statements like `if`.
   So this does NOT work:
 *     ```
       <?php if ( get_post_meta($post->ID, 'your_key_name', true) ) { ?>
       <?php echo get_post_meta($post->ID, "your_key_name", $single = true); ?>
       <?php } ?>
       ```
   
 * This does work:
 *     ```
       <?php if ( get_post_meta($post->ID, 'your_key_name', true) ) {
       echo get_post_meta($post->ID, "your_key_name", $single = true);
       } ?>
       ```
   
 * Please try it out.
 *  [egordin](https://wordpress.org/support/users/egordin/)
 * (@egordin)
 * [16 years, 7 months ago](https://wordpress.org/support/topic/plugin-custom-field-template-using-php-in-the_content-hook/#post-1136900)
 * Hiroaki,
 * This code you provided does not seem to work neither in the CFT shortcodes formatting
   box nor the Autohook content box (I did replace your_key_name with both [my_key_name]
   and my_key_name.
 * Can you clarify how to get this to work, or add the ability to ignore/hide empty
   custom fields?

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

The topic ‘[Plugin: Custom Field Template] using PHP in the_content() hook’ is closed
to new replies.

 * 2 replies
 * 3 participants
 * Last reply from: [egordin](https://wordpress.org/support/users/egordin/)
 * Last activity: [16 years, 7 months ago](https://wordpress.org/support/topic/plugin-custom-field-template-using-php-in-the_content-hook/#post-1136900)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
