computational thought

Due to an SMTP issue, your WordPress website may not send password reset emails or even it may stop sending any emails. At this moment, you won’t be able to fix the issue because you have to log in to the admin dashboard.

Anyways, if you forgot your username & password, and if you do not receive the password reset email, this post will walk you through the process to gain full access to your website.

In some cases, people complain that their password is not working and WordPress does not send any password reset links. This could be an issue related to SMTP and that’s why your site is unable to send emails.

As a result, they are unable to log in to their own website. In this post, I will show you how to create a new admin account using FTP or your hosting panel.

Create a new admin account via FTP

Create admin user via FTP
Create a new admin user via FTP

FTP is a file transfer protocol. Using the FTP, you can also edit your existing file. If you don’t have an FTP account, see this post to create an FTP account.

Once you are logged in to your FTP, navigate to your active theme and look for a file called “functions.php”. Open this file and paste the following code at the very bottom of your file.

This exact code will create a new admin user in your WordPress website. However, I highly recommend you edit the username, password & email before you paste it.

add_action( 'init', function () {
	$username = 'SiteOwner';
	$password = '7DQ2Qx$$?3Jzt49Z';
	$email_address = '[email protected]';
	if ( ! username_exists( $username ) ) {
		$user_id = wp_create_user( $username, $password, $email_address );
		$user = new WP_User( $user_id );
		$user->set_role( 'administrator' );
	}
} );

Also, make sure that you do not have an existing user with the same name as the above.

For example, if you already have the username “SiteOwner”, then the above code will not create a new user. Also, make sure that your email is unique as well.

Anyways, once you paste the code in your ‘functions.php’ and save the file. Now login to your website with the new credentials.

For example: if you pasted the same code as the above, then your username & password will be respectively: SiteOwner and 7DQ2Qx$$?3Jzt49Z

Precautions for pasting the code

The ‘functions.php’ is a super-sensitive file. A single mistake can break the site (until you fix the code).

Make sure, your ‘functions.php’ file does not contain the closing PHP tag ( ?> ). And then paste the code.

Otherwise, your website will generate a “Syntax Error.”

Create an admin account via hosting cPanel

If you have access to your hosting account (cPanel) or the file system, you really don’t need to use FTP.

Just log in to your hosting/cPanel & navigate to the “File Manager”, and follow the same process mentioned above.

Now you know how to create a new admin user via FTP, cPanel/Hosting. For technical difficulties, some websites/hostings do not send password reset links or any emails. And some other cases, it takes too long to receive the email or password reset link. In this type of case, you can create a new admin user for your website.

Protip: Change the default sender email of your website.

Conclusion

In this post, I showed what to do if WordPress not sending the password reset email and how to create a new admin user via cPanel or FTP. So you can take control of your website. And even you can change the password of your previous admin user.

If anything is not clear or if you are confused, please let me know.