Sensible Year Range for Gravity Forms Date Drop-Downs
Sets the years offered in Gravity Forms date drop-downs to a range that fits your form, such as the last 100 years for birth dates or the next two years for bookings.
Opens WPIDE on
Code
$wpide_gf_years_back = 100;
$wpide_gf_years_forward = 2;
add_filter( 'gform_date_min_year', function () use ( $wpide_gf_years_back ) {
return (int) wp_date( 'Y' ) - $wpide_gf_years_back;
} );
add_filter( 'gform_date_max_year', function () use ( $wpide_gf_years_forward ) {
return (int) wp_date( 'Y' ) + $wpide_gf_years_forward;
} );
Notes
Applies to date fields using the drop-down input type; adjust how many years back and forward to offer.
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.