The register_form WordPress PHP action fires after the ‘Email’ field in the user registration form, allowing you to add custom fields or content to the registration form.
Usage
add_action('register_form', 'your_custom_function');
function your_custom_function() {
// your custom code here
}
Parameters
- None
More information
See WordPress Developer Resources: register_form
Examples
Add a custom field to the registration form
This example adds a ‘Phone Number’ field to the registration form.
add_action('register_form', 'add_phone_number_field');
function add_phone_number_field() {
echo '<p><label for="phone_number">' . __('Phone Number') . '<br />';
echo '<input type="text" name="phone_number" id="phone_number" class="input" /></label></p>';
}
Add a Terms and Conditions checkbox
This example adds a ‘Terms and Conditions’ checkbox to the registration form.
add_action('register_form', 'add_terms_and_conditions_checkbox');
function add_terms_and_conditions_checkbox() {
echo '<p><label><input type="checkbox" name="terms_and_conditions" value="1" /> ';
echo __('I agree to the Terms and Conditions.') . '</label></p>';
}
Add a custom select field
This example adds a ‘How did you hear about us?’ select field to the registration form.
add_action('register_form', 'add_how_did_you_hear_about_us_field');
function add_how_did_you_hear_about_us_field() {
echo '<p><label for="hear_about_us">' . __('How did you hear about us?') . '<br />';
echo '<select name="hear_about_us" id="hear_about_us">';
echo '<option value="">' . __('Select') . '</option>';
echo '<option value="google">' . __('Google') . '</option>';
echo '<option value="friend">' . __('Friend') . '</option>';
echo '<option value="other">' . __('Other') . '</option>';
echo '</select></label></p>';
}
Add a custom section with a heading
This example adds a custom section with a heading to the registration form.
add_action('register_form', 'add_custom_section');
function add_custom_section() {
echo '<h2>' . __('Custom Section') . '</h2>';
echo '<p>' . __('Add your custom content here.') . '</p>';
}
Add a reCAPTCHA field
This example adds a reCAPTCHA field to the registration form. Note that you will need to replace YOUR_RECAPTCHA_SITE_KEY with your actual reCAPTCHA site key.
add_action('register_form', 'add_recaptcha_field');
function add_recaptcha_field() {
echo '<div class="g-recaptcha" data-sitekey="YOUR_RECAPTCHA_SITE_KEY"></div>';
}