Reset a WordPress admin password
Three ways back into a WordPress site you are locked out of, from the safest to the last resort.
Three methods, in the order you should try them. Applies to all shared and reseller hosting.
1. The "Lost your password?" link
Try this first. It needs nothing but access to the mailbox on the account.
- Go to your login page, normally
https://example.com/wp-admin. - Select Lost your password?
- Enter your username or email address, then Get New Password.
- Follow the link in the email you receive.
If no email arrives, the site cannot send mail — which is a separate problem worth fixing regardless. See Why mail from your PHP script fails. Use method 2 in the meantime.
2. Softaculous in cPanel
Works when the site cannot send mail, and does not involve editing any code.
- Log in to cPanel and open WordPress Manager by Softaculous.
- Find the installation and select the pencil (edit) icon.
- Scroll to Admin Account and enter a new password in Admin Password.
- Save, then sign in to the site.
This only lists installations Softaculous knows about. If yours is missing, use Scan to detect it, or use method 3.
3. Set the password from functions.php
The last resort. It works when nothing else does, and it briefly puts a plaintext password in a file inside your web root.
-
Connect over FTP or open cPanel's File Manager.
-
Go to
wp-content/themes/and open your active theme's folder. -
Download a copy of
functions.phpbefore changing it. A syntax error in this file takes the whole site down, including the login page you are trying to reach. -
Add this line immediately after the opening
<?phptag:wp_set_password( 'new_password', 1 );Replace
new_passwordwith the password you want. The1is the user ID;1is usually the first administrator, but not always. -
Save and upload.
-
Load any page on the site once — the code runs on page load, not on save.
-
Sign in with the new password.
-
Remove the line immediately and upload the file again.
Leaving that line in place resets the password on every single page load, so you will be unable to change it from the dashboard afterwards — it will revert on the next request. Remove it as soon as you are in.
Two further cautions: edit the theme you are actually using, or nothing happens; and if the theme updates, your edit is overwritten, which is harmless here but means the change may vanish before you have used it.
Afterwards
- Set a long, unique password, generated rather than invented.
- If you were locked out unexpectedly rather than by forgetting, treat the site as possibly compromised — check the user list under Users for accounts you did not create.
Related
Install and enable LiteSpeed Cache
Turn on LSCache from cPanel or from WordPress, and understand what each section of the plugin does before you change anything.
Improve a slow WordPress or WooCommerce dashboard
Find what is actually making wp-admin slow, then fix it — in the order that finds the cause fastest rather than a list of everything possible.