WPBeginner

Beginner's Guide for WordPress

  • Blog
    • Beginners Guide
    • News
    • Opinion
    • Showcase
    • Themes
    • Tutorials
    • WordPress Plugins
  • Start Here
    • How to Start a Blog
    • Create a Website
    • Start an Online Store
    • Best Website Builder
    • Email Marketing
    • WordPress Hosting
    • Business Name Ideas
  • Deals
    • Bluehost Coupon
    • SiteGround Coupon
    • WP Engine Coupon
    • HostGator Coupon
    • Domain.com Coupon
    • Constant Contact
    • View All Deals »
  • Glossary
  • Videos
  • Products
X
☰
Beginner's Guide for WordPress / Start your WordPress Blog in minutes
Choosing the Best
WordPress Hosting
How to Easily
Install WordPress
Recommended
WordPress Plugins
View all Guides

WPBeginner» Blog» Tutorials» How to Add an Admin User in WordPress using FTP

How to Add an Admin User in WordPress using FTP

Last updated on July 8th, 2016 by Editorial Staff
480 Shares
Share
Tweet
Share
Pin
Free WordPress Video Tutorials on YouTube by WPBeginner
How to Add an Admin User in WordPress using FTP

Being locked of your WordPress admin is frustrating. That’s why we have shown you how to add an admin user in WordPress via MySQL. Recently one of our readers asked if it was possible to add an admin user in WordPress using FTP. Ofcourse it is. In this article, we will show you how to add an admin user in WordPress using FTP.

Adding an admin user in WordPress using FTP

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

Sometimes you may forget your username or email address on a WordPress site and cannot login to the admin area.

One way to do this is by adding an admin user to the WordPress database using MySQL. But you may be unable to connect to phpMyAdmin or don’t want to run MySQL queries directly.

Some users may get their site hacked and admin account deleted. In that case, adding an admin user using FTP can quickly restore your access to the WordPress admin area.

Having said that, let’s see how you can easily add an admin user in WordPress using FTP access.

Adding an Admin User in WordPress Using FTP

First thing you will need is an FTP client. If you are new to using FTP, then see our guide on how to use FTP to upload files in WordPress.

Once connected to your WordPress site, you need to locate your WordPress theme’s functions.php file. It would be at a location like this:

/yoursite.com/wp-content/themes/your-current-theme/functions.php

Right click on functions.php file and then select download. Your FTP client will download the functions.php file to your computer.

Downloading functions.php file to edit

Open the file you just downloaded on your computer using a plain text editor like Notepad. Now you need to add this code at the bottom of the file.

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.

Next, save the file and then upload it back to your website using the FTP client.

You can now visit your WordPress site’s login area and sign in with the user account you just added.

Once you have logged in to your WordPress site, please edit the functions.php file and delete the code you added. Deleting the code will not remove the user you added, and you can always add new users and authors to your WordPress site.

We hope this article helped you learn how to add an admin user to WordPress using FTP. You may also want to see our list of 13 vital tips and hacks to protect your WordPress admin area.

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.

480 Shares
Share
Tweet
Share
Pin
Popular on WPBeginner Right Now!
  • How to Start Your Own Podcast (Step by Step)

    How to Start Your Own Podcast (Step by Step)

  • Revealed: Why Building an Email List is so Important Today (6 Reasons)

    Revealed: Why Building an Email List is so Important Today (6 Reasons)

  • Google Analytics in WordPress

    How to Install Google Analytics in WordPress for Beginners

  • Checklist

    Checklist: 15 Things You MUST DO Before Changing WordPress Themes

About the Editorial Staff

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi. Trusted by over 1.3 million readers worldwide.

The Ultimate WordPress Toolkit

21 Comments

Leave a Reply
  1. imran says:
    Oct 2, 2020 at 2:08 am

    worked, Thanks!!

    Reply
    • WPBeginner Support says:
      Oct 2, 2020 at 9:32 am

      You’re welcome :)

      Reply
  2. Kim H says:
    Jun 7, 2020 at 1:39 am

    Worked like a charm. Thank you for this article!

    Reply
    • WPBeginner Support says:
      Jun 9, 2020 at 8:33 am

      You’re welcome :)

      Reply
  3. Donovan says:
    May 15, 2020 at 5:54 am

    Worked perfectly. Thanks for the great advice.

    Reply
    • WPBeginner Support says:
      May 15, 2020 at 9:05 am

      Glad our article was helpful :)

      Reply
  4. Peter says:
    Mar 27, 2020 at 8:51 pm

    Thanks! It worked!

    Reply
    • WPBeginner Support says:
      Mar 30, 2020 at 9:02 am

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

      Reply
  5. Rogério says:
    Jan 30, 2019 at 11:22 am

    Nice work

    Reply
    • WPBeginner Support says:
      Jan 30, 2019 at 1:22 pm

      Thanks :)

      Reply
  6. adam says:
    Apr 2, 2018 at 4:02 am

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

    Reply
  7. Warner Mendenhall says:
    Feb 8, 2018 at 10:28 pm

    Thank you. Worked perfectly.

    Reply
  8. charu says:
    Oct 10, 2017 at 1:52 am

    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

    Reply
  9. Shafaq says:
    Jun 23, 2017 at 9:02 pm

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

    Reply
  10. Stef says:
    Apr 25, 2017 at 3:22 pm

    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?

    Reply
  11. Rdas says:
    Dec 14, 2016 at 12:54 am

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

    Reply
  12. Guille says:
    Oct 3, 2016 at 6:39 am

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

    Reply
  13. Hardeep says:
    Jul 11, 2016 at 2:11 am

    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

    Reply
  14. Toni Weidman says:
    Jul 8, 2016 at 9:39 am

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

    Reply
    • Patrick Johanneson says:
      Jul 8, 2016 at 2:40 pm

      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.

      Reply
    • Andre says:
      Jul 22, 2016 at 6:58 pm

      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).

      Reply

Leave a Reply Cancel 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.

Over 1,320,000+ Readers

Get fresh content from WPBeginner

Featured WordPress Plugin
OptinMonster
OptinMonster
Convert website visitors into email subscribers. Learn More »
How to Start a Blog How to Start a Blog
I need help with ...
Starting a
Blog
WordPress
Performance
WordPress
Security
WordPress
SEO
WordPress
Errors
Building an
Online Store
Useful WordPress Guides
    • 7 Best WordPress Backup Plugins Compared (Pros and Cons)
    • How to Fix the Error Establishing a Database Connection in WordPress
    • Why You Need a CDN for your WordPress Blog? [Infographic]
    • 30 Legit Ways to Make Money Online Blogging with WordPress
    • Self Hosted WordPress.org vs. Free WordPress.com [Infograph]
    • Free Recording: WordPress Workshop for Beginners
    • 24 Must Have WordPress Plugins for Business Websites
    • How to Properly Move Your Blog from WordPress.com to WordPress.org
    • 5 Best Contact Form Plugins for WordPress Compared
    • Which is the Best WordPress Popup Plugin? (Comparison)
    • Best WooCommerce Hosting in 2021 (Comparison)
    • How to Fix the Internal Server Error in WordPress
    • How to Install WordPress - Complete WordPress Installation Tutorial
    • Why You Should Start Building an Email List Right Away
    • How to Properly Move WordPress to a New Domain Without Losing SEO
    • How to Choose the Best WordPress Hosting for Your Website
    • How to Choose the Best Blogging Platform (Comparison)
    • WordPress Tutorials - 200+ Step by Step WordPress Tutorials
    • 5 Best WordPress Ecommerce Plugins Compared
    • 5 Best WordPress Membership Plugins (Compared)
    • 7 Best Email Marketing Services for Small Business (2021)
    • How to Choose the Best Domain Registrar (Compared)
    • The Truth About Shared WordPress Web Hosting
    • When Do You Really Need Managed WordPress Hosting?
    • 5 Best Drag and Drop WordPress Page Builders Compared
    • How to Switch from Blogger to WordPress without Losing Google Rankings
    • How to Properly Switch From Wix to WordPress (Step by Step)
    • How to Properly Move from Weebly to WordPress (Step by Step)
    • Do You Really Need a VPS? Best WordPress VPS Hosting Compared
    • How to Properly Move from Squarespace to WordPress
    • How to Register a Domain Name (+ tip to get it for FREE)
    • HostGator Review - An Honest Look at Speed & Uptime (2021)
    • SiteGround Reviews from 4464 Users & Our Experts (2021)
    • Bluehost Review from Real Users + Performance Stats (2021)
    • How Much Does It Really Cost to Build a WordPress Website?
    • How to Create an Email Newsletter the RIGHT WAY (Step by Step)
    • Free Business Name Generator (A.I Powered)
    • How to Create a Free Business Email Address in 5 Minutes (Step by Step)
    • How to Install Google Analytics in WordPress for Beginners
    • How to Move WordPress to a New Host or Server With No Downtime
    • Why is WordPress Free? What are the Costs? What is the Catch?
    • How to Make a Website in 2021 – Step by Step Guide
Deals & Coupons (view all)
Rocket coupon code
Rocket Coupon
Get 50% OFF on Rocket managed WordPress hosting plans for 3 months.
SendinBlue Coupon Code
Sendinblue Coupon
Get Sendinblue, a powerful marketing automation toolkit for small businesses, for FREE.
Featured In
About WPBeginner®

WPBeginner is a free WordPress resource site for Beginners. WPBeginner was founded in July 2009 by Syed Balkhi. The main goal of this site is to provide quality tips, tricks, hacks, and other WordPress resources that allows WordPress beginners to improve their site(s).

Join our team: We are Hiring!

Site Links
  • About Us
  • Contact Us
  • FTC Disclosure
  • Privacy Policy
  • Terms of Service
  • Free Blog Setup
  • Free Business Tools
  • Growth Fund
Our Sites
  • OptinMonster
  • MonsterInsights
  • WPForms
  • SeedProd
  • Nameboy
  • RafflePress
  • Smash Balloon
  • AIOSEO

Copyright © 2009 - 2021 WPBeginner LLC. All Rights Reserved. WPBeginner® is a registered trademark.

Managed by Awesome Motive | WordPress hosting by SiteGround | WordPress Security by Sucuri.