How To Prevent Spaces In WordPress Usernames

WordPress allows users to use spaces in their usernames, which is not a really great idea for the websites with open registrations. You wouldn’t want to confuse your users in spaces and stuff, so it’s a better idea to prevent spaces in WordPress username for the sake of your WordPress.

Non-technical users often pick a username with spaces and it’s so hard for them to remember their username. So, it’s your job to make this stuff easy for them & more neat for your database. You wouldn’t want someone to register twice to your website.

Just add following snippet to your current theme’s functions.php file to prevent spaces in WordPress usernames: