wordpress tips and tricks, wordpress tips

Select Dropdown Countries Template for WordPress developers

Last updated on September 11th, 2025 by Adnan





Hello WordPressers,

I was working on a project where I had to add the countries dropdown on the signup page. So, for making select dropdown countries selection sticky in the case of error at signup, I needed to check the $_POST[‘countries’] with every option in the select dropdown. It seems a redundant effort to me as It took me 30 mins to do this task.




So, I am sharing this code with you people to free you from this 30 mins hassle.  In return all I need is a ‘Thank you’ !!!

 

Select Dropdown Countries Template for WordPress developers

 

Method: 1

This method is posted in our comments section.

http://pastie.org/10673271

Method: 2

Share on




4 responses to “Select Dropdown Countries Template for WordPress developers”

  1. Abdussamad Avatar

    Ooh this is a mess! Use an associative array and a foreach loop and you’ll be done in a few lines *and* the code will actually be maintainable.

    Example:


    'Pakistan', 'IN' => 'India' ) ; //so on
    ?>

    $name ) { ?>
    <option value="" >
    <?php
    }

    1. Abdussamad Avatar

      Uggh looks like the WP comment filter removed my code example. I’ve put it on pastie:

      http://pastie.org/10673271

      1. captian Avatar

        wow, I liked your approach.
        updating this tutorial.

        @Abdussamad Thanks for your input.

  2. Steve Avatar
    Steve

    Thank you

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.