How to easily add an Admin user in WordPress using FTP

A problem often encountered when you have to help a customer with his WordPress and they are unable to give you their Admin access codes or you have simply misplaced them. There is an easy solution via FTP.

Before you begin, make sure that you have an FTP client as Filezilla. When you are connected to your WordPress site via FTP, you must locate your WordPress theme’s function.php file. See link below:

/yoursite.com/wp-content/themes/your-theme/functions.php

You can then right-click on functions.php file and download it. Your FTP client will download the functions.php file to your computer.

When the file is downloaded onto your computer, you can open the file using a plain text editor like Notepad. One crucial step is to add the code below at the bottom of the file.

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’);

Make sure you replace the Username, Password and email with your own values.

After the above steps, you can save the file and upload it back to your website using FTP client.

You can then go to WordPress site’s login area and sign in with the user account that you have just created.

Important!

Once you have logged in to your WordPress site, you will need to edit the functions.php file and delete the code you added. (Take note that deleting the code will not remove the user you added). Hence, adding new users and authors to your WordPress site will be possible.