Sometimes we lose access to the WordPress site backend, and we need to regain it. We may lose access due to various reasons like forgetting the user name and password, site hacked, etc. If you have only FTP access to the site, In that situation, you can create a new admin user very easily via FTP.
So, we will learn how to create WordPress admin via FTP in this tutorial.
How to Add an Admin User in WordPress using FTP
For creating administrator, First you need to connect via FTP. You can use third party FTP client like Filezilla, Winscp etc.to connect your site.
Once login to the site, Go the the active theme function.php file. Add the below code to the function.php file and save it.
function wpb_admin_account(){ $user = 'Username'; $pass = 'Password'; $email = 'email@domain.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');
In the above code, replace the following:
- $user with the username
- $pass with the desired password
- $email with the email address
Now open the following URl in your browser
yoursite.com/wp-login.php
When you open this url, the above code will execute. It creates the new admin into the database. Now fill the respective details and login with the new admin. You can delete the code from the function file after getting the access to your site.