Trusted WordPress tutorials, when you need them most.
Beginner’s Guide to WordPress
WPB Cup
25 Million+
Websites using our plugins
16+
Years of WordPress experience
3000+
WordPress tutorials
by experts

How to Add an Admin User in WordPress Using FTP (Easy Tutorial)

Losing access to your WordPress admin area can be a nightmare, especially when you’re facing a tight deadline or managing a client’s site.

At WPBeginner, we’ve helped countless users regain control of their websites after being locked out due to forgotten passwords, security plugin mishaps, or even hacking attempts.

While there are several ways to regain access, one of the most reliable methods is adding a new admin user through FTP (File Transfer Protocol). If you’ve never done this before, we’ll walk you through the process of adding an admin user via FTP, step-by-step.

How to Add an Admin User in WordPress Using FTP

When You May Need to Add an Admin User in WordPress Using FTP

Adding a WordPress admin user using FTP instead of the WordPress admin area might be necessary in a few situations:

  • Lost admin access – If you can’t get into your WordPress admin dashboard because you forgot your password, a security plugin locked you out, or there’s a problem with a plugin or theme, then you can create a new admin user through FTP to regain access.
  • Corrupted WordPress – Sometimes, you may experience some common WordPress errors where you can’t reach the admin dashboard. Creating a new admin user via FTP can help you get control back.
  • Security issues – If your site gets hacked and the hacker gains admin access, then making a new admin user can help you kick them out and secure your site.
  • Migration problems – When migrating your site (like from localhost to a live server), if there are issues with the admin user not working or you need to reset the info, then making a new admin user with FTP can be a quick fix.

With that in mind, we will walk you through a step-by-step guide on how to easily add an admin user to your WordPress website using FTP.

Pro Tip: Need help with your WordPress website ASAP? Our emergency WordPress support can come to your rescue. Whether you’re experiencing downtime or your site was hacked, we can get your site back online fast.

How to Add a New Admin Account in WordPress With FTP

First things first, you will need an FTP client. This software allows you to access WordPress without logging in to your dashboard.

Besides adding a new admin account, you can also deactivate plugins and bulk-install your favorite plugins.

We will be using FileZilla in this tutorial, as it’s pretty easy to use.

Next, you will need to connect your website with the FTP client. To do this, you will need your FTP access details (usually accessible in cPanel or other hosting control panels).

For step-by-step guidance, you can see our guide on how to use FTP to upload files in WordPress.

Once your FTP client is connected to your website files, you will need to find your current WordPress theme’s functions.php file. You should be able to locate the file on the right side of the FTP window, inside your current theme’s folder, which is found in a path like this:

/public_html/wp-content/themes/your-current-theme/

Here’s what our screen looks like. Our demo site is using the default Twenty Twenty-Four theme.

Locating functions.php file in FTP

Once you have found the functions.php file, you can just double-click it. FileZilla will then download the file to your computer.

At this stage, just go ahead and locate that file on your computer. After that, open it using a plain text editor like Notepad.

Then, you need to insert this code snippet at the bottom of the file to add an admin user account:

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

Don’t forget to replace Username, Password, and email@domain.com with your own values. You can also use the same code snippet to create other user roles if needed.

Here’s what the file should look like:

Adding the new admin user account code in functions.php

Next, simply save the file and go back to your FTP client.

Here, you need to locate the file you just edited on the left side of the interface. Right-click on it, and click ‘Upload.’

Uploading the functions.php file via FTP

A new window will pop up saying that the file already exists in your website files.

Just select the ‘Overwrite’ option and click ‘OK.’

Overwriting an existing functions.php file via FTP

Now, open yourwebsitename.com/wp-admin in your browser. Remember to replace yourwebsitename.com with your own domain name.

If the code works, then you will be able to type your credentials into the login page and access the WordPress admin area again.

The default WordPress login page

Note: Once you have logged in to your WordPress site, you should go back to your FTP client to open the functions.php file again and delete the code you added.

Deleting the code will not remove the user. This is just to ensure that the code does not execute again, which could lead to unintended consequences. Plus, you can always add new users and authors to your WordPress site if needed.

Alternative: Add a New Admin User With Your Web Host’s File Manager

If your FTP connection was not successful and you are still locked out of the WordPress admin, then you can use your WordPress hosting’s file manager to add the code to functions.php. Beginners may also find this method much easier.

For the sake of this tutorial, we will use Bluehost’s file manager. In your hosting dashboard, just go to the ‘Websites’ tab, find the WordPress website you are locked out of, and click ‘Settings.’

Bluehost site settings

Once inside, scroll down to the Quick Links section.

Then, click ‘File Manager.’

Bluehost File Manager button

The same as the previous method, you need to find your current WordPress site’s functions.php file.

After you locate it, just right-click on the file and select ‘Edit.’

Editing a functions.php file in Bluehost file manager

Next, simply paste the same code snippet from the earlier method.

Click ‘Save Changes.’

Adding an add new admin user code in the WordPress functions.php file using Bluehost file manager

All you need to do next is go to your WordPress login URL and try signing in with your new admin user’s login details.

Bonus: Learn More WordPress functions.php Hacks

Besides adding a new admin user, there are actually a lot of cool tricks you can do with the functions.php file.

For example, you could add new widget areas that are not default in your WordPress theme. This way, you have more space to insert your widgets.

You can learn more about all of these hacks in our ultimate list of useful tricks for the WordPress functions.php file.

And if you want to try out all of these tips and tricks, then we recommend using WPCode. While it’s possible to edit functions.php with an FTP client, WPCode makes it safe and easy to manage all of the different code snippets that you add to the file.

This way, you can keep track of every custom code snippet that’s been added and disable it in a few clicks if an error occurs.

You can read more in our full WPCode review.

WPCode

We hope this WordPress tutorial helped you learn how to add an admin user to WordPress using FTP. You may also want to see our articles on how to view and control WordPress cron jobs and how to disable wp-cron in WordPress and set up proper cron jobs.

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

Disclosure: Our content is reader-supported. This means if you click on some of our links, then we may earn a commission. See how WPBeginner is funded, why it matters, and how you can support us. Here's our editorial process.

Editorial Staff

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi with over 16 years of experience in WordPress, Web Hosting, eCommerce, SEO, and Marketing. Started in 2009, WPBeginner is now the largest free WordPress resource site in the industry and is often referred to as the Wikipedia for WordPress.

The Ultimate WordPress Toolkit

Get FREE access to our toolkit - a collection of WordPress related products and resources that every professional should have!

Reader Interactions

32 CommentsLeave a Reply

  1. Jiří Vaněk

    I couldn’t believe it could be so simple to add an admin to WordPress using the `functions.php` file. I’ve saved this guide because I’ve needed to grant access to WordPress for another user several times and always did it the complicated way through PHPMyAdmin. That’s not always available, and FTP might be the only solution in some cases. This is a very useful tutorial that also perfectly demonstrates how powerful the `functions.php` file can be in WordPress and what can be done with it.

  2. Dennis Muthomi

    The instructions are super helpful especially the part about editing the functions.php file. I lost admin access once due to a plugin conflict and this method saved me. A tip I’d add is to always backup your site before making changes. That way if anything goes wrong during the process you can restore your site back to its previous state.

  3. Moinuddin Waheed

    This is a must have guide for every wordpress user.
    in the past i have been in situation where the admin login dashboard got locked and I was not able to login again. infact I have lost one such website of mine in the past due to lack of knowledge.
    Thanks for this useful guide.

  4. Mrteesurez

    This is good. I don’t know it is this possible to create an admin user through FTP, that for the guide.
    I see this as a back up idea or knowledge all WordPress users must have in case one lose access to admin area.

  5. Faisal

    Worked like a charm.

    Thank you

    • WPBeginner Support

      You’re welcome!

      Admin

  6. Piotr Szcześniak

    Never remeber the snippet so I’m happy to frequently visit you guys! Thx!

  7. Thomas Hansen

    If you are using a child theme is it then the functions.php of the child theme, that you need to insert the code into?

    • WPBeginner Support

      Yes, you would want to add the code there.

      Admin

  8. André Cassiano

    Worked like a charm! Tks.

    • WPBeginner Support

      Glad our guide was able to help :)

      Admin

  9. imran

    worked, Thanks!!

    • WPBeginner Support

      You’re welcome :)

      Admin

  10. Kim H

    Worked like a charm. Thank you for this article!

    • WPBeginner Support

      You’re welcome :)

      Admin

  11. Donovan

    Worked perfectly. Thanks for the great advice.

    • WPBeginner Support

      Glad our article was helpful :)

      Admin

  12. Peter

    Thanks! It worked!

    • WPBeginner Support

      You’re welcome, glad our guide was helpful :)

      Admin

  13. Rogério

    Nice work

    • WPBeginner Support

      Thanks :)

      Admin

  14. adam

    Thanks man it worked even in Wordpress version 4.9.0
    Many Thanks brother !

  15. Warner Mendenhall

    Thank you. Worked perfectly.

  16. charu

    Is any way to delete that entry from database that I have created through function.php i.e delete the last created user for using admin area.

    Thanks

  17. Shafaq

    good explanation but there is an error with my code. user role changed if go into user profile page otherwise no effect . can you please elaborate.

    here is my code

    $level = $profileuser->ihc_user_levels ;
    $id = $profileuser->id ;
    $u= new WP_User( $id ) ;

    if ( $level==’3′) {
    echo ‘user level ‘.$level;
    echo ‘user id ‘.$id;
    $u = wp_update_user( $u->set_role( ‘featured’ ) );
    }

  18. Stef

    I got the big problem that this new user has first to be activated..

    Is it possible to set the activation of the user by function or did I lose and I need to install a backup on my wordpress via ftp?

  19. Rdas

    I have latest WordPress version will it work for me or need to change anything on the code?

  20. Guille

    Great explanation. Thank you so much for this tip. It works like a charm!

  21. Hardeep

    Hello,

    Really informative post, I am developer and sometimes I have to contact sys admin to reset or create new wp user for testing.

    This is very good way, thanks for sharing

  22. Toni Weidman

    How secure is this going to be on an FTP host?

    • Patrick Johanneson

      Not very. So the first thing you should do once you’re logged back in is change the password on that new admin account. Then remove the code from functions.php.

    • Andre

      Start with SFTP with an FTP client (program) that has that. But as Patrick mentioned, you NEED to change your password once you are back in. I don’t mean a simple password either, always make sure you use at least 12 characters mixed with numbers, symbols, lower and uppercase letters (avoid using words).

Leave A Reply

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.