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

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

Editorial Note: We earn a commission from partner links on WPBeginner. Commissions do not affect our editors' opinions or evaluations. Learn more about Editorial Process.

Do you need to add an admin user in WordPress with FTP?

At WPBeginner, we often help users who get locked out of their WordPress admin area and need to find a way back in. One easy fix is to add an admin user using FTP (File Transfer Protocol).

In this article, we will show you how to add an admin user in WordPress using FTP.

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 moving your site to a new 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.

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 files from your website without logging in to your WordPress dashboard. 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:


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 add this code snippet at the bottom of the file to add an admin user account:

function wpb_admin_account(){
$user = 'Username';
$pass = 'Password';
$email = '';
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' );
} }

Don’t forget to replace Username, Password, and 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 in your browser. Remember to replace 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 or WooCommerce theme’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 also disable automatic update email notifications, which can get annoying if you have a lot of plugins and themes that auto-update.

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 article on how to add a WordPress admin user to the MySQL database with phpMyAdmin and our ultimate WordPress SEO guide to boost your rankings.

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

29 CommentsLeave a Reply

  1. Syed Balkhi says

    Hey WPBeginner readers,
    Did you know you can win exciting prizes by commenting on WPBeginner?
    Every month, our top blog commenters will win HUGE rewards, including premium WordPress plugin licenses and cash prizes.
    You can get more details about the contest from here.
    Start sharing your thoughts below to stand a chance to win!

  2. Thomas Hansen says

    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?

  3. charu says

    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.


  4. Shafaq says

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

  5. Stef says

    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?

  6. Hardeep says


    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

    • Patrick Johanneson says

      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 says

      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.