InMotion Hosting Support Center
Occasionally, there is a need to provide a way to add users to the WordPress Administrator without using its interface. This method can be used to add users of any role that you have defined within WordPress. Once you add the function, use it only to add a user and then remove the code when it is complete. Follow the directions below:

Adding a WordPress User through the Theme Functions.php File


  1. You will need to have administrator access to the installation files for your WordPress installation. You can use FTP or a file manager like the one available in cPanel. There are multiple options depending on the system used by your host. However you access your files, use that option now and navigate to the location where you have installed your WordPress files.
  2. Once you see the files for your WordPress installation, open the WP-CONTENT folder and then open the THEMES folder underneath it.
  3. Once you are in the Themes folder, locate the folder for the theme that you are using with your WordPress installation. Open that theme folder.
  4. Search for functions.php file, then open it in an editor so that you can edit it.
  5. Copy and paste the following function into the Functions.php file:

    function 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','admin_account');
    

    Make sure that you change username, password, and email to something unique or this function will not work. The username, password and email that you use are the criteria applied to the user. This function has been tested with WordPress version 4.9.7.

  6. Save changes.

Verifying the User Addition

When you have saved the file, simply reload your website and then login to the WordPress Administrator. Verify that your user has been added. Remember that when you have completed adding the user that you should remove the added code from your functions.php file.
Was this article helpful?
Continued Education in Course 208:Managing WordPress Installations
You are viewing Section 2: How to Add a WordPress Administrator User through PHP
Section 3: How do I add Google Analytics to WordPress without a plugin?

Post a Comment

Name:
Email Address:
Phone Number:
Comment:
Submit

Please note: Your name and comment will be displayed, but we will not show your email address.

0 Questions & Comments

Post a comment

Back to first comment | top

Need more Help?

Search

Ask the Community!

Get help with your questions from our community of like-minded hosting users and InMotion Hosting Staff.

Current Customers

Chat: Click to Chat Now E-mail: support@InMotionHosting.com
Call: 888-321-HOST (4678) Ticket: Submit a Support Ticket

Not a Customer?

Get web hosting from a company that is here to help. Sign up today!