Adding a new wordpress user using code (function.php)

We can create new user in wordpress using function.php with wp_create_user function.

$username =”user_john”; //username
$password = “john_pass”; //password
$mail =”sample@sample.com”; //email
if ( !username_exists( $username )  && !email_exists( $mail ) ) {
$user_id = wp_create_user( $username, $password, $mail );
$user = new WP_User( $user_id );
$user->set_role( ‘author’ ); //either of ‘administrator’, ‘subscriber’, ‘editor’, ‘author’, ‘contributor’
}

Reload the website.