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.

How can I add a field to the WordPress Register form? For example, I want to add the "First Name" field in the users profile to the Register form, but I can't figure out how to do that.

The field's name is first_name, but adding <input type="text" name="first_name" id="first_name" value="<?php echo $_POST['first_name']; ?>" required="required" placeholder="<?php _e('First Name'); ?>" /> doesn't work for some reason. The form submits fine, but the profile doesn't get the "First Name" field filled in in the back end.

I'm editing this plugin to tweak the register form: http://wordpress.org/extend/plugins/s8-custom-login-and-registration/

share|improve this question
add comment

2 Answers 2

I don't know about the plugin you are using, but the way to add custom fields to the registration form and saving it to user profile is by hooking into register_form action hook to output the field and then using the appropriate filter/action hook to update/save user profile.

Your case, for example:

<?php
// output the form field
add_action('register_form', 'ad_register_fields');
function ad_register_fields() {
?>
    <p>
        <label for="firstname"><?php _e('First Name') ?><br />
        <input type="firstname" name="firstname" id="firstname" class="input" value="<?php echo esc_attr($_POST['firstname']); ?>" size="25" tabindex="20" />
        </label>
    </p>
<?php
}

// save new first name
add_filter('pre_user_first_name', 'ad_user_firstname');
function ad_user_firstname($firstname) {
    if (isset($_POST['firstname'])) {
        $firstname = $_POST['firstname'];
    }
    return $firstname;
}
?>
share|improve this answer
    
So this would add it to the default WordPress registration form, correct? –  Rev Dec 13 '12 at 21:24
    
Yes, that is correct. –  Ahmad M Dec 14 '12 at 8:37
    
@Ahmad M Is there any way to validation for these additional fields? –  Vasanthan.R.P Apr 6 '13 at 5:08
add comment
up vote 0 down vote accepted

I found an excellent, free plugin that gets the job done.

http://wordpress.org/extend/plugins/user-registration-aide/

Very easy to use, adds fields to both the register and the profile pages.

share|improve this answer
add comment

Your Answer

 
discard

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.