Skip to content
Eduardo Lira

WORDPRESS · PHP

How to Enable Access to the WordPress Admin Panel with Email Address

Learn how to allow access to the WordPress admin panel using the email address as the username. This guide shows how to add a conditional code to your theme's functions.php file to facilitate login if you forget your username.

In case you forget your WordPress administrative access user, enable access with the Email address in the user field. To do this, simply add the conditional code below in the functions.php file of the theme. The file is located inside the theme directory. For example, in this path: wp-content/themes/themename/functions.php

function login_with_email_address($username) {
$user = get_user_by_email($username);

if(!empty($user->user_login)){
$username = $user->user_login;
return $username;
}
}
add_action('wp_authenticate','login_with_email_address');

In case of doubts, leave your comment. Hugs!

Revisited in November 2026

This post is from 2012. Since WordPress 4.5, from April 2016, logging in with an e-mail comes built in: the login field accepts the username or the e-mail, with no code at all. If your installation is that version or newer, don’t add the snippet above.

Reviewing the code, it also had two problems:

  • The get_user_by_email function has been deprecated since WordPress 3.3. The current form is get_user_by( 'email', $email ).
  • To swap the username, the function has to take the parameter by reference, with &$username. Without the &, the change stays inside the function and WordPress keeps receiving the original text.

Who writes this

Eduardo Lira

Software developer in Rio de Janeiro. I started this blog in 2012, in technical support at a hosting company, writing down the fixes for the problems that came up every day. Today I work at Sofis Tecnologia, on critical healthcare systems and SQL Server database migrations.

Found a mistake in this post?

A command that no longer works, a broken link, wrong information: tell me what you saw. The message goes only to the author and is not shown on the site.