How to Create an admin User with functions.php

Adding an Admin User in WordPress

Once connected to your WordPress site, you need to locate your WordPress theme’s functions.php file. It would be at a location like this:
/yoursite.com/wp-content/themes/your-current-theme/functions.php

Now you need to add this code at the bottom of the file.

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

Leave a Comment

Your email address will not be published.