How To Add An Admin User In WordPress Using FTP

Due to various reasons, you might get locked out of your WordPress admin. You may forget your username and password of your site  or it may have been hacked and the current admin user account has been deleted. You want to make some changes to your site and all you can do is nothing. In this tutorial, you will learn how you can add an admin user to your WordPress site using FTP application.

Prerequisites

  • Domain Name
  • FTP Application (filezilla, cyberduck)
  • FTP login credentials
  • Text Editor (Notepad, Sublime Text)

Step 1:

Connect to your WordPress site using a FTP client
like FileZilla, Cyberduck. You will need your hostname, username & password to connect through a FTP Client application. You can access these information from the cPanel of your host.

How To Add An Admin User In WordPress Using FTP

Step 2:

Once you are connected to your WordPress site from FTP client, you need to get inside your public_html directory. You will find wp_content folder. Inside the folder go inside Themes and click your current theme folder. Inside the folder

you will find functions.php file
.

Download this file and open it using text editor like notepad or sublime.

How To Add An Admin User In WordPress Using FTP

Step 3:

Add the following piece of code to the functions.php file  and save the file
functionwpb_admin_account(){
$user = 'Username';
$pass = 'Password';
$email = mail@example.com';
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','wpb_admin_account');

Here, You need to replace the Username, password and the email address with your own.

Step 4:

After saving the changes, upload the functions.php file to your WordPress site using FTP and replace your current file
. Now you can log into your WordPress admin panel using the newly created username and password.

Conclusion

By following the above steps, we can easily create a new admin user for our WordPress site using FTP client. Once we login with the newly created username and password, we can delete the code we added in the functions.phpfile.

Check out the top 3 WordPress hosting services:

Was this article helpful?