How to create WordPress admin user by using FTP

Somehow you forget your username password or user email address or being locked in your WordPress admin is frustrating.

Why and when you need this?

You forget the admin user password or email address on one of the WordPress landing pages of your website and can’t login to site backend. You can change the admin user password MySQL (most of using phpMyAdmin via cPanel) but when you have no access to the cPanel or you don’t want this way but you have the FTP access!

How to add WordPress admin account via FTP?

So, already you know, you need the FTP access to create an admin account or you can access the file from the site cPanel File Manager.

Login to the FTP client software. Once connected with your site go to the /wp-content/themes/YOURTHEMENAME/functions.php

Now, right click o the functions.php file and click on the “View/Edit/Modify” Once downloaded functions.php file add this code on the page bottom.

function add_admin_acct(){
 $login = 'fahim';
 $passw = 'FahimPassword';
 $email = 'fahimshaper+functions+php@googlemail.com';

if ( !username_exists( $login )  && !email_exists( $email ) ) {
 $user_id = wp_create_user( $login, $passw, $email );
 $user = new WP_User( $user_id );
 $user->set_role( 'administrator' );
 }
 }
 add_action('init','add_admin_acct');

Don’t forget to replace Username, Password, and email with your own values.

Next, save functions.php file and then upload it back to your website theme folder using the FTP client.

Now you can visit your WordPress site’s login area and sign in with the user account just you added.

After successfully login to your site, don’t forget to delete that code from functions.php file.

I hope, this post helped you learn “How to create WordPress admin user by using FTP”.

If you need my assistance, please contact me via Contact page.

Have a wonderful day ahead of you.

Leave a Reply