WordPress Administration Password Reset - WordPress Tutorials functions.php

Have you or your client ever lost the WordPress Administrator Login and been unable to login to your WordPress site? We've had clients that after we finished the website build they took over and managed the website and chose to removed our admin account. A few years later they returned and wanted updates to the website. The problem is that they don't remember their login password and they've removed our administrator login. As long as you have FTP access you can quickly create a new admin account.

With your FTP access, download the functions.php file from the active theme. Use the code below to create a new administrator account to gain access to the WordPress admin area. Now you can login to WordPress and create a new administrator account (Users > Add New).

After your new administrator account is working we recommend removing the admin account snippet from the functions.php file.

Be sure to check out our other WordPress code recipes by clicking here.

Adding Admin Account in functions.php


function add_admin_acct(){
	$login = 'yourlogin';
	$passw = 'password';
	$email = 'myacct1@mydomain.com';

	if ( !username_exists( $login )  && !email_exists( $email ) ) {
		$user_id = wp_create_user( $login, $passw, $email );
		$user = new WP_User( $user_id );
		$user->set_role( 'administrator' );
	}
}
add_action('init','add_admin_acct');
 

Check out more great WordPress tutorials and tips by clicking here!

You must be logged in to post a comment.
Menu