WebGee Docsالتوثيق
WordPress

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.

Try this first. It needs nothing but access to the mailbox on the account.

  1. Go to your login page, normally https://example.com/wp-admin.
  2. Select Lost your password?
  3. Enter your username or email address, then Get New Password.
  4. 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.

  1. Log in to cPanel and open WordPress Manager by Softaculous.
  2. Find the installation and select the pencil (edit) icon.
  3. Scroll to Admin Account and enter a new password in Admin Password.
  4. 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.

  1. Connect over FTP or open cPanel's File Manager.

  2. Go to wp-content/themes/ and open your active theme's folder.

  3. Download a copy of functions.php before changing it. A syntax error in this file takes the whole site down, including the login page you are trying to reach.

  4. Add this line immediately after the opening <?php tag:

    wp_set_password( 'new_password', 1 );

    Replace new_password with the password you want. The 1 is the user ID; 1 is usually the first administrator, but not always.

  5. Save and upload.

  6. Load any page on the site once — the code runs on page load, not on save.

  7. Sign in with the new password.

  8. 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.

On this page