Ask any question about WordPress here... and get an instant response.
How can I add a custom field to a WordPress registration form?
Asked on Nov 01, 2025
Answer
To add a custom field to a WordPress registration form, you can use the "user_register" action hook to capture and save the custom field data. This involves modifying the registration form and processing the input data.
<!-- BEGIN COPY / PASTE -->
// Add a custom field to the registration form
function my_custom_register_form() {
?>
<p>
<label for="custom_field"><?php _e('Custom Field','textdomain') ?><br />
<input type="text" name="custom_field" id="custom_field" class="input" value="<?php echo esc_attr( wp_unslash( $_POST['custom_field'] ?? '' ) ); ?>" size="25" /></label>
</p>
<?php
}
add_action('register_form', 'my_custom_register_form');
// Save the custom field data
function my_custom_user_register($user_id) {
if (isset($_POST['custom_field'])) {
update_user_meta($user_id, 'custom_field', sanitize_text_field($_POST['custom_field']));
}
}
add_action('user_register', 'my_custom_user_register');
<!-- END COPY / PASTE -->Additional Comment:
- This code snippet adds a text input field to the registration form and saves the input as user meta data.
- Ensure that you replace 'textdomain' with your theme or plugin's text domain for translation purposes.
- Remember to validate and sanitize all input data to maintain security.
- Consider using a plugin like "User Registration" for more advanced features without coding.
Recommended Links:
