Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

Add custom input to digits form

Paste code into your theme functions.php. I hope it’s working on the registration form.

functions.php

// Displaying the field
function wp_registration_form() {
    $year = ! empty( $_POST['year_of_birth'] ) ? intval( $_POST['year_of_birth'] ) : '';
    ?>
    <p>
        <label for="year_of_birth"><?php esc_html_e( 'Year of birth', 'wp' ) ?><br/>
            <input type="number" min="1900" max="2017" step="1" id="year_of_birth" name="year_of_birth" value="<?php echo esc_attr( $year ); ?>"class="input"/>
        </label>
    </p>
    <?php
}
add_action( 'register_form', 'wp_registration_form' );

// Validating the field
function wp_registration_errors( $errors, $sanitized_user_login, $user_email ) {

    if ( empty( $_POST['year_of_birth'] ) ) {
        $errors->add( 'year_of_birth_error', __( '<strong>ERROR</strong>: Please enter your year of birth.', 'wp' ) );
    }

    if ( ! empty( $_POST['year_of_birth'] ) && intval( $_POST['year_of_birth'] ) < 1900 ) {
        $errors->add( 'year_of_birth_error', __( '<strong>ERROR</strong>: You must be born after 1900.', 'wp' ) );
    }

    return $errors;
}
add_filter( 'registration_errors', 'wp_registration_errors', 10, 3 );

// Sanitizing and saving the field
function wp_user_register( $user_id ) {
    if ( ! empty( $_POST['year_of_birth'] ) ) {
        update_user_meta( $user_id, 'year_of_birth', intval( $_POST['year_of_birth'] ) );
    }
}
add_action( 'user_register', 'wp_user_register' );

/**
 * Back end registration
 */

function wp_admin_registration_form( $operation ) {
    if ( 'add-new-user' !== $operation ) {
        // $operation may also be 'add-existing-user'
        return;
    }

    $year = ! empty( $_POST['year_of_birth'] ) ? intval( $_POST['year_of_birth'] ) : '';

    ?>
    <h3><?php esc_html_e( 'Personal Information', 'wp' ); ?></h3>

    <table class="form-table">
        <tr>
            <th><label for="year_of_birth"><?php esc_html_e( 'Year of birth', 'wp' ); ?></label> <span class="description"><?php esc_html_e( '(required)', 'wp' ); ?></span></th>
            <td>
                <input type="number"
                   min="1900"
                   max="2017"
                   step="1"
                   id="year_of_birth"
                   name="year_of_birth"
                   value="<?php echo esc_attr( $year ); ?>"
                   class="regular-text"
                />
            </td>
        </tr>
    </table>
    <?php
}
add_action( 'user_new_form', 'wp_admin_registration_form' );

// Validating the field
function wp_user_profile_update_errors( $errors, $update, $user ) {
    if ( $update ) {
        return;
    }

    if ( empty( $_POST['year_of_birth'] ) ) {
        $errors->add( 'year_of_birth_error', __( '<strong>ERROR</strong>: Please enter your year of birth.', 'wp' ) );
    }

    if ( ! empty( $_POST['year_of_birth'] ) && intval( $_POST['year_of_birth'] ) < 1900 ) {
        $errors->add( 'year_of_birth_error', __( '<strong>ERROR</strong>: You must be born after 1900.', 'wp' ) );
    }
}
add_action( 'user_profile_update_errors', 'wp_user_profile_update_errors', 10, 3 );
add_action( 'edit_user_created_user', 'wp_user_register' );

// Profile display
function wp_show_extra_profile_fields( $user ) {
    ?>
    <h3><?php esc_html_e( 'Personal Information', 'wp' ); ?></h3>

    <table class="form-table">
        <tr>
            <th><label for="year_of_birth"><?php esc_html_e( 'Year of birth', 'wp' ); ?></label></th>
            <td><?php echo esc_html( get_the_author_meta( 'year_of_birth', $user->ID ) ); ?></td>
        </tr>
    </table>
    <?php
}
add_action( 'show_user_profile', 'wp_show_extra_profile_fields' );
add_action( 'edit_user_profile', 'wp_show_extra_profile_fields' );

Output screen:
enter image description here

Related Posts:

  1. Verify signup via SMS? [closed]
  2. Custom Sign Up Form for a Custom WordPress Website
  3. Allow user to select a theme to install when they signup
  4. “Password Strength Unknown” Registration Issue
  5. Custom Registration Template/Page
  6. How to Block Access to Standard Login Flow and Comment Flow
  7. Need to manually regsiter user, send the password and retreive their user ID
  8. wpmu_signup_user_notification filter not working
  9. How to make wp-signup.php a 1-step process [closed]
  10. Function like is_registration_page to check if current page is registration page
  11. Stuck with WordPress Multisite Custom signup page without .htaccess modification
  12. How to disable user registration for the default subscriber user role?
  13. Send custom signup approval email to different Administrators selectively
  14. How to bypass the username as a required field in registration and just use email address instead?
  15. Change wp-signup.php Page Template
  16. Redirect user to a form until they have filled it out [closed]
  17. Correct passwords keep appearing as incorrect
  18. Redirect user to previous page after signup from custom form
  19. Setup page on first login on multisite
  20. How can I add custom meta on signup page and pass along to be used after blog activation?
  21. Users are being redirected to main site when trying to register on subsite of my Multisite network
  22. What is a good free subscribe list?
  23. How can I manually activate a new site in a wordpress multisite network?
  24. Mailing list sign up form without plugin
  25. Retrieve duration since sign up
  26. How to change a user role after registering in multisite?
  27. Allowing users to Sign-up > Login > Post articles that need approval
  28. Facebook Registration Tool: how to use in WordPress? [closed]
  29. show something only when user comes from specific page at remote host?
  30. How do I add a sign up form to my blog?
  31. Display number of sign-ups [closed]
  32. How can I create a basic PHP that can lives outside WP?
  33. How to add user registration and signup in WordPress and create members only page?
  34. signup_user() throws fatal error
  35. Integrate otp in my custom singup form
  36. When i try to open Localhost/wordpress/wp-admin . An Error appears ” Registration Has been Disabled” . No login page is shown in the browser
  37. Using custom IDP with WP
  38. How the wordpress login and signup in react native app
  39. I want to signin from first wordpress site to other wordpress website without registration..without using network mode
  40. How to redirect a referal url to a signup page?
  41. Set User Role based on age result from Facebook Log-In – WordPress
  42. How user should automatically activated and go for login?
  43. Creating custom pages for new users automatically
  44. How to auto create site after user sign up on multisite(network)
  45. Multisite “Skip Confirmation Email” Log Out Problem
  46. Multisite/Network What file to edit to change the “new blog” registration text
  47. How does adding custom meta to signup form work?
  48. Set user role based on invitation code
  49. wp-signup.php example template
  50. What plugin(s) are best for this User registration task? [closed]
  51. Change All Login/Signup Links in Plugin
  52. A conditional button
  53. Create service similar to wordpress.com [closed]
Categories signup Tags signup
calling a custom field value inside functions.php
Set front_page programatically after user login via query, while leaving site option alone

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress