How to change username before submitting in login form ?

I have used mobile number as username when a user registers in site. also I have removed 0 from the beginning of the mobile number. Now in login form I need to remove 0 from the beginning of the mobile number, if user enter the mobile number with 0. Is there a function to use as an action in functions.php

1 Answer 1


You can use wp_authenticate filter for that... This filter is fired before the user is authenticated. Params are passed by reference, so you can modify them.

// user name is passed in by reference 
function wp_authenticate_by_email( &$username ) {
    // make sure that the condition below works for you
    if ( is_numeric( $username ) && '0' == substr( $username, 0, 1 ) ) {
        $username = substr( $username, 1 );
add_action( 'wp_authenticate', 'wp_remove_leading_zero_from_phone_number' );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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