Friendly usernames for auto-created WordPress users

Our Google Apps Login Premium and Enterprise plugins allow all users with an email address in an organization’s Google Apps domain to log in to the WordPress site with one click. If the user doesn’t have an account in WordPress already, one is automatically created based on their Google profile information – taking their first name and last name, for example. The plugin needs to generate a unique WordPress username, so the simplest thing is for it to use the email address as the username directly. This ensures it is unique – but an email address can be long and cumbersome as a username when used throughout the site.

Wouldn’t it be great if you could impose a way to generate shorter usernames for your site that you know are unique? Our extensible platform means that you can!

If you or your developer add the following to your Theme’s functions.php, or to another point in your site, any new auto-created usernames should take the shorter form – e.g. john.smith instead of

If you’re not comfortable extending your site with the code below, you can try activating a version of this code that is self-contained in plugin form – download our ZIP file then Add New / Upload from your Plugins page.

function my_gal_sanitize_username($username, $userinfo) {
  $parts = explode("@", $username);
  if (count($parts) == 2) {
     $username = $parts[0];
  return $username;

add_filter('gal_sanitize_username', 'my_gal_sanitize_username', 10, 2);

The code or plugin should work with the latest versions of Google Apps Login Premium or Enterprise (2.8.6 or higher). Please get in touch with any questions or feedback!

Google Apps Login is trusted by thousands of organizations from small businesses to NASDAQ-listed companies and government organizations.

Users click their way through Login via Google (just one click after the first time)

Users click their way through Login via Google (just one click after the first time)

You can try it out by clicking below to auto-create a test account on this site! This will show you the basic Google login process.
Try out Google login

Logging in is only the start – Google Apps Login takes care of all your WordPress user management. Find out more here.