Absolutely YES, you can achieve this. WordPress requires a username. We must provide a username.
Don’t edit WordPress core code.
We can achieve this by hiding username field, get email and store it as username.
Remove Username textfield
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | add_action('login_head', function(){ ?> <style> #registerform > p:first-child{ display:none; } </style> <script type="text/javascript" src="<?php echo site_url('/wp-includes/js/jquery/jquery.js'); ?>"></script> <script type="text/javascript"> jQuery(document).ready(function($){ $('#registerform > p:first-child').css('display', 'none'); }); </script> <?php }); |
Remove Username error
1 2 3 4 5 6 7 8 9 10 11 | //Remove error for username, only show error for email only. add_filter('registration_errors', function($wp_error, $sanitized_user_login, $user_email){ if(isset($wp_error->errors['empty_username'])){ unset($wp_error->errors['empty_username']); } if(isset($wp_error->errors['username_exists'])){ unset($wp_error->errors['username_exists']); } return $wp_error; }, 10, 3); |
Manipulate Background Registration Functionality.
1 2 3 4 5 | add_action('login_form_register', function(){ if(isset($_POST['user_login']) && isset($_POST['user_email']) && !empty($_POST['user_email'])){ $_POST['user_login'] = $_POST['user_email']; } }); |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.