Title: [Plugin: Advanced Custom Fields] Allow PHP in field &#039;Default Value&#039;
Last modified: August 20, 2016

---

# [Plugin: Advanced Custom Fields] Allow PHP in field 'Default Value'

 *  [Kenneth Jensen](https://wordpress.org/support/users/kennethj/)
 * (@kennethj)
 * [13 years, 8 months ago](https://wordpress.org/support/topic/plugin-advanced-custom-fields-allow-php-in-fields-default-value/)
 * Hi there
 * I’m using ACF and i’m quite impressed. But one major feature request would be
   to allow PHP in the Default Value field.
 * Example:
    I need a custom field with the post’s slug as default value, and this
   would be easy to fill in with something like
 *     ```
       <?php $slug = $post->post_name;
       echo $slug;>
       ```
   
 * Could you please consider this?
 * [http://wordpress.org/extend/plugins/advanced-custom-fields/](http://wordpress.org/extend/plugins/advanced-custom-fields/)

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

 *  [refreshingdesign](https://wordpress.org/support/users/refreshingdesign/)
 * (@refreshingdesign)
 * [12 years, 9 months ago](https://wordpress.org/support/topic/plugin-advanced-custom-fields-allow-php-in-fields-default-value/#post-3041875)
 * Did you ever find a way to do this?
 *  Thread Starter [Kenneth Jensen](https://wordpress.org/support/users/kennethj/)
 * (@kennethj)
 * [12 years, 9 months ago](https://wordpress.org/support/topic/plugin-advanced-custom-fields-allow-php-in-fields-default-value/#post-3041876)
 * No, sadly not.
 *  [Ov3rfly](https://wordpress.org/support/users/ov3rfly/)
 * (@ov3rfly)
 * [12 years, 9 months ago](https://wordpress.org/support/topic/plugin-advanced-custom-fields-allow-php-in-fields-default-value/#post-3041877)
 * You could use a filter of ACF via your theme `functions.php`, something like 
   this:
 * A field named `my_field`, insert name at `name=` in `add_filter()` line.
 * A default value of `php_default_hack` for that field.
 *     ```
       function my_acf_load_value( $value, $post_id, $field ) {
       	if ( $value == 'php_default_hack' ) {
       		// do your php magic here...
       		$value = 'this is set from php';
       	}
       	return $value;
       }
       add_filter( 'acf/load_value/name=my_field', 'my_acf_load_value', 10, 3 );
       ```
   
 * The code does this: If your field has the value `php_default_hack` during load,
   the value will be replaced by `this is set from php`.
 * See also [http://www.advancedcustomfields.com/resources/filters/acfload_value/](http://www.advancedcustomfields.com/resources/filters/acfload_value/)
 * For your example, note that a new created post has no slug = post_name yet.

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

The topic ‘[Plugin: Advanced Custom Fields] Allow PHP in field 'Default Value'’ 
is closed to new replies.

 * ![](https://ps.w.org/advanced-custom-fields/assets/icon.svg?rev=3207824)
 * [Advanced Custom Fields (ACF®)](https://wordpress.org/plugins/advanced-custom-fields/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/advanced-custom-fields/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/advanced-custom-fields/)
 * [Active Topics](https://wordpress.org/support/plugin/advanced-custom-fields/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/advanced-custom-fields/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/advanced-custom-fields/reviews/)

## Tags

 * [ACF](https://wordpress.org/support/topic-tag/acf/)
 * [php](https://wordpress.org/support/topic-tag/php/)

 * 3 replies
 * 3 participants
 * Last reply from: [Ov3rfly](https://wordpress.org/support/users/ov3rfly/)
 * Last activity: [12 years, 9 months ago](https://wordpress.org/support/topic/plugin-advanced-custom-fields-allow-php-in-fields-default-value/#post-3041877)
 * Status: not resolved