Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I want to add some more profile fields to Wordpress. It works fine with normal text box:

<input type="text" name="gender" id="gender" value="<?php echo esc_attr( get_the_author_meta( 'gender', $user->ID ) ); ?>" class="regular-text" /><br />

But of cause I don't want my users to enter "male" or "female". So I need a select box! :)

May you please help me how I have to change the code above to get a select box?!

Thanks a lot!

share|improve this question

1 Answer 1

up vote 2 down vote accepted

Place the following code in your functions.php

    add_action( 'show_user_profile', 'show_extra_profile_fields' );
    add_action( 'edit_user_profile', 'show_extra_profile_fields' );

    function show_extra_profile_fields( $user ) { ?>
        <h3>Extra profile information</h3>
        <table class="form-table">
                <th><label for="gender">Gender</label></th>
                    <select name="gender" id="gender" >
                        <option value="Male" <?php selected( 'Male', get_the_author_meta( 'gender', $user->ID ) ); ?>>Male</option>
                        <option value="Female" <?php selected( 'Female', get_the_author_meta( 'gender', $user->ID ) ); ?>>Female</option>
    <?php }

    add_action( 'personal_options_update', 'save_extra_profile_fields' );
    add_action( 'edit_user_profile_update', 'save_extra_profile_fields' );

    function save_extra_profile_fields( $user_id ) {
        if ( !current_user_can( 'edit_user', $user_id ) )
            return false;
        update_usermeta( $user_id, 'gender', $_POST['gender'] );
share|improve this answer
Perfect! Thank you very much! There was just a "save" to much - here: add_action( 'edit_user_profile_update', 'save_save_extra_profile_fields' ); –  Philipp Nov 21 '11 at 9:23
how can we change the order of the extra fields? I like it to be the first even before Personal Options –  alex May 17 '13 at 9:16

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.