How To Create New WordPress Admin User Account Via FTP

Creating a new user account on WordPress is a piece of cake. All you have to do is head over to the Users admin page, where you can create your new account.

This takes no more than a few seconds. Once you’re done, you will be ready to log in with your username and password.


If, however, you lose access to your WordPress admin account, what do you do?

Do you panic, make a bunch of calls, or close your eyes and take a couple of deep breaths? Or do you stay calm, knowing that we always have the perfect solution for you?

The latter, of course! We have a function to save your admin life in this very situation.

Whatever the reason may be for the loss of control over your #admin #account, you can retake charge in no time. Click To Tweet

Create Admin account via FTP

Sometimes, you may be able to access only your FTP server with the HTTP server remaining out of reach. In this case, you have to create a new admin account. This, although a rare case, can be rectified with the given function.

To create a new account outside the WordPress admin environment, all you need is the FTP access to your WordPress site. Being the admin, you should have the necessary information to log in to your server.

There are some actual places where you can place a piece of code, and it can create a new admin account for you, like function.php in your themes. Any code added to function.php gets executed while loading the WordPress theme.

The step-by-step guide illustrated below shall take you through the process of creating a new user account via FTP:

    1. Open the FTP client and connect to your account.
    2. Navigate to wp-content/themes
    3. Open the folder of the theme that is currently in use.
    4. Look for the functions.php file and edit it.
    5. Copy the following function and paste it into the file.
function create_admin_account(){
$user = 'Username';
$pass = 'Password';
$email = '';
//if a username with the email ID does not exist, create a new user account
if ( !username_exists( $user ) && !email_exists( $email ) ) {
$user_id = wp_create_user( $user, $pass, $email );
$user = new WP_User( $user_id );
//Set the new user as a Admin
$user->set_role( 'administrator' );
} }
  1. Change the username, password, and email ID.
  2. Save the changes.

The new email ID, password, and username must be unique, or the function may not work correctly.

After saving the changes, you may navigate to the WP login panel, and log in with your new information. Once you have successfully verified your account, you can delete the function from the functions.php file.

The given function creates an admin account, but it can create an account with a user role just as easily, with only a few modifications. All you need to do is change the role in the 8th row of the code to whichever user role you create (author, subscriber, contributor, etc.)


If unfortunately, you lose your admin account, you shall end up losing all posts that had been written under that name. It is essential, thereby, that you keep a backup which can easily be retrieved if needed.

Once you logged in with your new Admin user ID, you can reset the password of the old admin account. This way you do not lose any data.

Consider this an important reminder that must NOT be overlooked: If you don’t already have a backup, create it immediately. You may also want to see How to Hack Into a WordPress Website, The Complete Guide,  to see how to regain access to your WordPress account, to which you have the right to edit, access and administrate, in the event, you lose access.

Join our email list

Interesting articles about

WordPress and internet security

5 thoughts on “How To Create New WordPress Admin User Account Via FTP”

  1. It is of course much simpler than that.
    The code will never work as it calls the wrong function.
    Nevertheless i found his post super useful and exactly what I needed.

  2. FYI the function names don’t match between the declaration and add_action (create_admin_account vs admin_account). Otherwise works great!

  3. Hello Will and Mark

    Thank you both for pointing out the error, it was the wrong function name as Will noted – I have corrected the code 🙂

Leave a Reply to Lars Koudal Cancel Reply

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

Safe, Simple & Secure

WordPress Security made easy

Powerful, yet easy to use

Keep your website safe & prevent downtime due to security issues.

custom logoWP Security NinjaWP Security Ninja
5 Stars - Based on 78 User Reviews

We handle your WordPress security

We are PayPal verified.

20% OFF

Subscribe to our newsletter

* We do not spam or share your email

Discount on any Security Ninja plan

and get

Hi and welcome back :-)