For WordPress users, it can be quite frustrating to forget login credentials or face issues accessing their websites. Thankfully, there is a...


For WordPress users, it can be quite frustrating to forget login credentials or face issues accessing their websites. Thankfully, there is a solution that allows you to regain access by adding an admin user in WordPress using FTP (File Transfer Protocol). In this article, we will guide you through the process of adding an admin user using FTP, ensuring you can regain control of your WordPress website with ease.

Add Admin User in WordPress using FTP

Step 1: Connect to Your Website Using FTP

The first step is to establish an FTP connection with your website. To accomplish this, you'll need an FTP client such as FileZilla. Launch the FTP client and enter the necessary FTP credentials provided by your hosting provider. Once you've entered the details, click on the 'Quickconnect' button to establish the connection.

Step 2: Navigate to Your Website's Root Directory

After successfully connecting to your website using FTP, you'll need to navigate to the root directory. In most cases, this directory is named 'public_html.' However, if you have installed WordPress in a subdirectory, you should navigate to that specific location instead.

Step 3: Locate the functions.php File

Within the root directory, locate the functions.php file, which is typically found in the wp-content/themes/your-theme/ folder. The functions.php file is responsible for loading the functions of your theme. Right-click on the file and select either 'View/Edit' or 'Download,' depending on your FTP client.

Step 4: Add Code to the functions.php File

Using a text editor, open the functions.php file and insert the following code snippet at the end 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');
Ensure you replace 'Username,' 'Password,' and 'email@domain.com' with your desired values.

Step 5: Save and Upload the functions.php File

After adding the code snippet to the functions.php file, save the file and upload it back to the wp-content/themes/your-theme/ folder on your website using FTP. If prompted, overwrite the existing file.

Step 6: Log in with the New Admin User

You can now log in to your WordPress dashboard using the credentials of the new admin user you just created. Once logged in, it is recommended to update the password and email address for the new admin user to enhance security.

Conclusion

In conclusion, adding an admin user in WordPress using FTP is a straightforward process that can save you from trouble if you ever forget your login credentials or encounter login issues. Simply follow the steps outlined in this guide, and you'll be able to regain access to your website in no time. By utilizing FTP, you have the power to take control of your WordPress site and overcome any login-related obstacles that come your way.