WordPress : Add Admin User in WordPress By FTP client.

Code

Did You Forget WordPress Admin credentials?

How will you login now if forget Admin credentials?

This happens many times when we forget the login password of WordPress.

If you have FTP details then no need to worry about it. You can create new admin user using FTP.

Just paste this code to your theme’s functions.php.


function AddAdminAccount(){
  $user    = 'NewUsername';
  $pass    = 'Password';
  $email   = '[email protected]';
  $user_id = wp_create_user( $user, $pass, $email );
  $user    = new WP_User( $user_id );
  $user->set_role( 'administrator' );
}
add_action('init','AddAdminAccount');

Note: this code can give error if a user already exist with this “user name” and “user email” .

And if user not exist it will create new admin user with credential provided by you. but when you refresh page, code will run again , but this time user already exist.

So for removing this fetal error we need to precheck “user name” and “user email” if it already exist or not.

Example:


function AddAdminAccount(){
  $user    = 'NewUsername';
  $pass    = 'Password';
  $email   = '[email protected]';
  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' );
  } 
}
add_action('init','AddAdminAccount');

Please don’t forget to fill the username email password fields. And don’t forget to delete the code from your functions file after user creation.

Shiv kumawat

Executive Director & CEO

"Shiv kumawat is the Executive Director and CEO of Eoxys It Solution LLP and the strategic mind behind the company"s growth. His expertise in operational efficiency and team leadership empowers his colleagues to excel and innovate.”

Latest Posts

Factories of the Future: How AI is Powering a Manufacturing Revolution in the USA

  Factories of the Future: How AI is Powering a Manufacturing Revolution in the USA A New Era for American…

Shafeeq Khan
August 28, 2025

Reinventing Everyday Life: The Rise of Artificial Intelligence in Finance for 2025

  Reinventing Everyday Life: The Rise of Artificial Intelligence in Finance for 2025 A New Financial Landscape Artificial intelligence isnʼt…

Shafeeq Khan
August 14, 2025

AI in Retail USA Redefining Shopping, Operations, and Experiences in 2025

  AI in Retail USA: Redefining Shopping, Operations, and Experiences in 2025 How Artificial Intelligence Is Changing Retail in the…

Shafeeq Khan
August 11, 2025
,

Leave a Reply

Your email address will not be published. Required fields are marked *