Hey folks! Ever locked yourself out of your WordPress site? It happens to the best of us—maybe you forgot your password, got hacked, or a plugin went wrong. Don’t worry! You can add a new admin user right through FTP without needing to log in. This trick saves the day and gets you back in control fast. In this guide, we’ll walk you through it step by step. It’s simple, even if you’re not a tech whiz. Let’s get started!
Why Add an Admin User via FTP?
Sometimes, you can’t access the WordPress dashboard. Common reasons include:
- Forgotten admin password and no reset email.
- Security plugins blocking you out.
- Hacked site or corrupted files.
- Issues after moving your site to a new host.
Using FTP lets you edit files directly on the server to create a new admin account. It’s a quick fix that works when other methods fail.
0
What You’ll Need Before Starting
To follow this tutorial, make sure you have:
- An FTP client like FileZilla (it’s free and easy).
- Your FTP login details—username, password, host, and port. Check your hosting panel (like cPanel) for these.
- A plain text editor, such as Notepad or Notepad++.
If your host has a built-in file manager (like Bluehost does), you can skip the FTP client and do it there too.
Step-by-Step: Adding the Admin User
Follow these steps carefully. We’ll edit the functions.php file in your theme to run a small code that adds the new account.
- Connect to Your Site via FTP: Open your FTP client and enter your details to connect. Once in, go to your WordPress folder—usually /public_html/ or similar.
- Find the functions.php File: Navigate to /wp-content/themes/your-current-theme/. Right-click functions.php and download it to your computer.
- Edit the File: Open the downloaded file in your text editor. Scroll to the bottom and paste this code:
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');
Change ‘Username’, ‘Password’, and ’email@domain.com’ to your own info. Pick a strong password!
- Upload the Edited File: Save the changes and upload it back via FTP. Say yes to overwrite the old file.
- Log In to WordPress: Go to your site’s login page (like yoursite.com/wp-admin) and use the new username and password. You’re in!
That’s it for getting access. But don’t stop here—clean up next to keep things safe.
Cleanup: Remove the Code After Use
Once you’re logged in, go back to FTP:
- Download functions.php again.
- Delete the code you added.
- Upload the clean file back.
Why? The code runs every time the site loads, which isn’t needed anymore and could cause problems if left there. Removing it won’t delete your new user.
0
Tips and Warnings for Safety
- Use SFTP if Possible: It’s more secure than plain FTP to protect your files.
- Change the Password Right Away: Once in, update your new admin password in the WordPress dashboard.
- Backup First: Always back up your site before editing files—just in case.
- Alternative Way: If FTP isn’t working, use your host’s file manager to edit functions.php the same way.
- Stuck?: If the code doesn’t work, check if you’re editing the active theme’s file. Or reach out to your host for help.
These steps should work on most setups, but if your site is hacked, consider a full security check after regaining access.
Final Thoughts
Locking out of WordPress can be stressful, but adding an admin user with FTP is a simple rescue. It takes just minutes and no fancy tools. Now you’re back in business, ready to update your blog or fix issues. Remember, strong passwords and regular backups prevent this from happening again.
Happy WordPressing!