How to Add an Admin User in WordPress using FTP Print

  • add admin user wordpress
  • 9

How to Add an Administrator User in WordPress via FTP

Being locked out of the WordPress admin panel is frustrating. In this guide, we’ll show you how to create a new administrator user using FTP access.

When should you use this method?

  • If you have forgotten your username or password and cannot log in.
  • If you only have FTP access (e.g. after a site migration) but no admin credentials.
  • Alternatively, you can add an admin via phpMyAdmin by editing the wp_users table, but this requires cPanel access.

Step-by-step procedure

1. Connect via FTP

Use an FTP client (e.g. FileZilla) to connect to your hosting account.

2. Locate the functions.php file

Navigate to your active theme’s folder:

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

Download the functions.php file to your computer.

Download functions.php via FTP

3. Edit functions.php

Open the file with a plain text editor (e.g. Notepad) and add the following code at the bottom of the file, replacing it with your own values:

function add_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','add_admin_account');
  

Note: Replace Username, Password, and email@domain.com with your desired values.

4. Upload the modified file

Re-upload the modified functions.php file to the server, overwriting the existing one.

5. Log in to WordPress

Now visit the WordPress login page (https://yourdomain.com/wp-admin) and log in with the new credentials.

6. Remove the code

Once logged in, edit functions.php again and remove the code you added. The administrator account will remain active, but the extra code will no longer run.

⚠️ Warning: Leaving this code inside functions.php can create a security risk. Be sure to remove it immediately after creating the user.

Was this answer helpful?

« Back