How to display "US" as the first choice but leave the default country field blank?

Hi Yumei,

Avoid setting a default country, as it will be displayed first and may prevent the placeholder from being selected automatically. Therefore, I have set “Select” as the placeholder for the country so that it is initially selected.

I have combined two functions into one based on the documentation below to remove the US from the list initially and then add it back to the top of the list.

Please install the Code Snippets plugin or add the following code to your child theme’s functions.php file.

add_filter( 'gform_countries', 'modify_countries_list' );

function modify_countries_list( $countries ) {
    $key = array_search( 'United States', $countries );

    if ( $key !== false ) {
        unset( $countries[ $key ] );
    }

    // this time we'll add the US at the top of the list
    array_unshift( $countries, 'United States' );

    return $countries;
}

You’ll see the US stay at the 2nd position after the placeholder text.

Give it a try, and let me know how that goes! :smile:

1 Like