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.
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.
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:
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.’
A new window will pop up saying that the file already exists in your website files.
Just select the ‘Overwrite’ option and click ‘OK.’
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.
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.’
Once inside, scroll down to the Quick Links section.
Then, click ‘File Manager.’
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.’
Next, simply paste the same code snippet from the earlier method.
Click ‘Save Changes.’
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.
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.
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.
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.
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.
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.
Faisal
Worked like a charm.
Thank you
WPBeginner Support
You’re welcome!
Admin
Piotr Szcześniak
Never remeber the snippet so I’m happy to frequently visit you guys! Thx!
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
André Cassiano
Worked like a charm! Tks.
WPBeginner Support
Glad our guide was able to help
Admin
imran
worked, Thanks!!
WPBeginner Support
You’re welcome
Admin
Kim H
Worked like a charm. Thank you for this article!
WPBeginner Support
You’re welcome
Admin
Donovan
Worked perfectly. Thanks for the great advice.
WPBeginner Support
Glad our article was helpful
Admin
Peter
Thanks! It worked!
WPBeginner Support
You’re welcome, glad our guide was helpful
Admin
Rogério
Nice work
WPBeginner Support
Thanks
Admin
adam
Thanks man it worked even in Wordpress version 4.9.0
Many Thanks brother !
Warner Mendenhall
Thank you. Worked perfectly.
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
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’ ) );
}
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?
Rdas
I have latest WordPress version will it work for me or need to change anything on the code?
Guille
Great explanation. Thank you so much for this tip. It works like a charm!
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
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).