It is very frustrating if you lose access to your site backend. If you forget your username or you are fixing hacked WordPress site and need to regain access to the WordPress backend. You can access the backend by resetting the password or by creating a new admin user in WordPress.

Adding admin users in WordPress is very easy if you have FTP access. First, you need to connect your site via FTP. You can access site files via CPanel file manager or FTP client such as FileZilla.

How to Add an Admin User in WordPress using FTP

After connected to site files, you need to locate the theme function file for adding the code. You can find the theme function file on the following path:

Open the function.php file and add the following code:

function wpb_admin_account(){
$user = 'Username';
$pass = 'Password';
$email = '';
if ( !username_exists( $user ) && !email_exists( $email ) ) {
$user_id = wp_create_user( $user, $pass, $email );
$user = new WP_User( $user_id );
$user->set_role( 'administrator' );
} }
  • Replace ‘Username’ with new username
  • Replace ‘Password’ with desired password
  • ’’ with your new email

Save the file. After all the above steps, go to the WordPress login URL that is .

Login with a new username and password. Once login successfully, don’t forget to delete the code from the function.php file.



Pin It on Pinterest

Share This