Table of Contents
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
- 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.
- Once you see the files for your WordPress installation, open the WP-CONTENT folder and then open the THEMES folder underneath it.
- 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.
- Search for functions.php file, then open it in an editor so that you can edit it.
Copy and paste the following function into the Functions.php file:
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.
- 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.