Add New Users Without Logging Into WordPress

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.

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.

  1. Connect to your server through a FTP client such as FileZilla;
  2. Open your WordPress theme’s function.php file (this is often located in public_html > wp_content > themes > your_theme_folder;
  3. Copy and paste the code below and upload the saved file.
function new_admin_account(){
    $login = 'myusername';
    $password = 'mypassword1';
    $email = '';

    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' );

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.