Add Admin User in WordPress using FTP

Hello Developers,

Here you can find quick code for the Add Admin User in WordPress using FTP

Suppose if you forget your username or email address on a WordPress site and you don’t able login to the admin area. Like my below screenshot

Then here I will show you how to add Username and Password using FTP

Another way to Adding Username and Password is using database in mysql. But if you are unable to connect to phpMyAdmin. In that case you can adding username and password via FTP

Copy below code in your theme’s Function.php file.

function wpb_admin_account(){
$user = 'testusername'; // Add here Username
$pass = 'testpass123'; // Add here Password
$email = 'test@gmail.com'; // Add here 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' );
} }
add_action('init','wpb_admin_account');

Result:

When you removed this code from function.php file then don’t worry about it, user will not removed. You can remove from admin dashboard. So if you want to remove users then you have to remove them from admin.

Thank you and Keep coding 🙂

Blog Catagory : WORDPRESS