Created
February 11, 2026 20:38
-
-
Save kbcarte/dfb7ff8c019604293b239cfa4cb22c5a to your computer and use it in GitHub Desktop.
Gravity Forms put USA at top of drop downs for countries, including drop down in Address field type
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // Yoink: https://community.gravityforms.com/t/how-to-display-us-as-the-first-choice-but-leave-the-default-country-field-blank/17226/2 | |
| /** | |
| * Set US to top of countries list in Gravity Forms. | |
| */ | |
| // Normal way | |
| add_filter( 'gform_countries', 'modify_countries_list' ); | |
| function modify_countries_list( $countries ) { | |
| $key = array_search( 'United States', $countries ); | |
| if ( $key !== false ) { | |
| unset( $countries[ $key ] ); | |
| } | |
| array_unshift( $countries, 'United States' ); | |
| return $countries; | |
| } | |
| // Roots Sage way | |
| add_filter( 'gform_countries', function ( $countries ) { | |
| $key = array_search( 'United States', $countries ); | |
| if ( $key !== false ) { | |
| unset( $countries[ $key ] ); | |
| } | |
| array_unshift( $countries, 'United States' ); | |
| return $countries; | |
| } ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment