Tutorial, WordPress

How to Add User/Admin in WordPress: A Step-by-Step Guide using Code or FTP

Managing user accounts is a crucial aspect of running a WordPress site. There may be situations where you need to add a new user or an admin to your WordPress site, but you are not able to access the admin panel. In such cases, you can add users manually using code or FTP. In this post, we will guide you through the process of adding a user or an admin using both methods.

 

Adding an Admin in WordPress using FTP

  1. Connect to your WordPress site’s FTP and navigate to the “wp-content” folder.
  2. Inside the “wp-content” folder, locate the “themes” folder and open it. Navigate to the active theme’s folder and open the “functions.php” file.
  3. Add the following code to the end of the “functions.php” file:

 


/* Add New Admin User */
function wc_admin_account(){
    $user = 'admin';
    $pass = 'Password';
    $email = 'admin@yoursite.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','wc_admin_account');


 

  1. Replace “admin” with the desired username, and “admin@yoursite.com” with the desired email address.
  2. Save the changes to the “functions.php” file and upload it back to the active theme’s folder.
  3. Now, navigate to your WordPress site and log in using the newly created admin account.

In conclusion, adding a user or an admin to a WordPress site using code or FTP is a relatively simple process. By following the steps outlined in this post, you can quickly add new users and admins to your WordPress site without having to access the admin panel.

Leave a Reply

Your email address will not be published. Required fields are marked *