0

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/

3

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;
}
?>
| improve this answer | |
  • So this would add it to the default WordPress registration form, correct? – JacobTheDev Dec 13 '12 at 21:24
  • Yes, that is correct. – Ahmad M Dec 14 '12 at 8:37
  • 1
    @Ahmad M Is there any way to validation for these additional fields? – Vasanthan.R.P Apr 6 '13 at 5:08
  • Anyone knows how to add a field before username/email ? Everything is added after those two ... – trainoasis Aug 9 '16 at 8:26
0

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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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