Tulip Media

Entrepreneurial thoughts

BuddyPress – Create an automatic country dropdown list in profile field

Are you looking for a function that imports all countries of the world to a BuddyPress profile field called “Country”? This code is for you.

Consider that you open an international BuddyPress social network and you want let your users select their country. It's annoying to manually add countries one by one. The solution is to import all the countries with this piece of code, that you can find on GitHub.

Be careful, you have to copy and paste this code in the bp-custom.php file of your BuddyPress install. If you don't have this file, create it and upload it to the /wp-content/ folder, and add this code inside it:


function bp_add_custom_country_list() {

if ( !xprofile_get_field_id_from_name('Country') && 'bp-profile-setup' == $_GET['page'] ) {

$country_list_args = array(
'field_group_id' => 1,
'name' => 'Country',
'description' => 'Please select your country',
'can_delete' => true,
'field_order' => 2,
'is_required' => false,
'type' => 'selectbox',
'order_by' => 'custom'


$country_list_id = xprofile_insert_field( $country_list_args );

if ($country_list_id) {

$countries = array(
"Antigua and Barbuda",
“Bosnia and Herzegovina”,
“Burkina Faso”,
“Cape Verde”,
"Central African Republic",
" Congo Brazzaville) ",
“Costa Rica”,
" Ivory Coast ",
"Czech Republic",
“Dominican Republic”,
“East Timor (Timor Timur)”,
"El Salvador",
“Equatorial Guinea”,
" France ",
“Gambia, The”,
“Korea, North”,
“Korea, South”,
"Marshall Islands",
" Morocco ",
“New Zealand”,
“Papua New Guinea”,
“Saint Kitts and Nevis”,
“Saint Lucia”,
“Saint Vincent”,
"San Marino",
“Sao Tome and Principe”,
"Saudi Arabia",
“Serbia and Montenegro”,
" Sierra Leone ",
"Solomon Islands",
"South Africa",
"Sri Lanka",
"Trinidad and Tobago",
“United Arab Emirates”,
“United Kingdom”,
"United States",
"Vatican City",

foreach ($countries as $country) {

'field_group_id' => 1,
'parent_id' => $country_list_id,
'type' => 'option',
'name' => $country,
'option_order' => $i++


add_action('bp_init', 'bp_add_custom_country_list');


Then, visit the profile fields settings page at mydomain.com/wp-admin/users.php?page=bp-profile-setup

Once you visited the page, you can see the new field. So you can remove the piece of code in bp-custom.php, don't let it inside the file.

That's it! If this post helped you in your project, please share it and mention!


My latest tweets

New shorts on Blooness 👉 Training dedicated to the best oilseeds for health is finally available in audio format https://buff.ly/3xo9fTS

New shorts on Blooness 👉 If there was only one supplement to take, it would be magnesium (along with vitamin D). The complete guide to the best multivitamins on the market still available here with free access https://buff.ly/49bHqvp

New shorts on Blooness 👉 The latest Blooness training on #proteins is available in audio format https://buff.ly/4aijbMW

Load more

Don't miss business advice by email

No spam, just an email when new content is published.

2 Responses

    1. Hi!
      You need to write a similar code for all cities of the world, but it seems to be complicated as there are a lot of cities to list…

Leave a Reply

Your email address will not be published. Required fields are marked *