Ever need to add a new user without logging into the WordPress Dashboard? You can do this by editing your WordPress theme’s functions.php file.
2 answers
1
Creating a new user through the functions.php file
To add a new user without logging into your WordPress dashboard, you can use an FTP to edit your functions.php file to add a new user.
- Connect to your server through a FTP client such as FileZilla;
- Open your WordPress theme’s function.php file (this is often located in public_html > wp_content > themes > your_theme_folder;
- Copy and paste the code below and upload the saved file.
function new_admin_account(){ $login = 'myusername'; $password = 'mypassword1'; $email = 'myemail@mydomain.com'; if ( !username_exists( $login ) && !email_exists( $email ) ) { $user_id = wp_create_user( $login, $password, $email ); $user = new WP_User( $user_id ); $user->set_role( 'administrator' ); } } add_action( 'init', 'new_admin_account' );
— Support WizardAnswer 1
0
Security warning for test users!
If you’re just testing the above function, please note that the code creates a new user altogether. Therefore even after removing the function, you must delete the new user from WordPress by navigating to Users from your WordPress Dashboard.
— Support WizardAnswer 2