User Registration

  1. Home
  2. Docs
  3. User Registration
  4. How to?
  5. How to add default country in countries list?

How to add default country in countries list?

Currently, if you drag and drop the country field, Afganistan will be the default country. You may want default country to be the country of your choice. Add the following codes to your child theme’s functions.php

add_filter( 'user_registration_form_field_args', 'ur_add_default_country', 10, 3 );

function ur_add_default_country( $args, $key, $value ) {

        if ( $args['field_name'] === 'country_152873675' ) {
               $args['default'] = 'FR';
        }

        return $args;
}

Note your country field name. And your country code. If you are not sure about the country code check here

 

You may either want to add — Select a country — option to your countries list.  For that add the following codes to your child theme’s functions.php

add_filter( 'user_registration_countries_list', 'ur_filter_countries' );

function ur_filter_countries( $countries ) {
    $countries = array_reverse( $countries );

    $countries[] = __( '-- Select a country --', 'user-registration' );

    $countries = array_reverse($countries);

    return $countries;
}

 

It is strongly recommended NOT to change anything on child theme if you are not familiar with these kind of stuffs as a single error may result your site to crash.

Was this article helpful to you? Yes No

How can we help?