Default an ACF Date Field to Today
Pre-fills an empty ACF date picker with today's date on new posts, saving a click for fields like "published on" or "received".
Opens WPIDE on
Code
// Date picker field name.
$wpide_acf_today_field = 'received_date';
add_filter( 'acf/load_field/name=' . $wpide_acf_today_field, function ( $field ) {
if ( empty( $field['default_value'] ) ) {
$field['default_value'] = wp_date( 'Ymd' );
}
return $field;
} );
Notes
Uses the site's timezone. Saved dates are never changed.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.