computational thought

If you forgot your username & password, and if you’re unable to reset your password in WordPress, then this post is for you. In some cases, people complain that their password is not working and WordPress does not send any password reset links. 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 = 'siteowner@yoursite.com';
	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 pasted 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.