
How to Create an Admin User in WordPress using function
Don’t have a wp admin access? Don’t worry, it can be easily done via FTP. In this article, we will show you How to Create an Admin User in WordPress using function.
Connect FTP first and go the wordpress themes folder. In the themes folder there is function.php
file. Open the function.php
file on any editor like Notepad++, komodo edit
or something like that.
The location path will be like this: "/mysite.com/wp-content/themes/my-theme/functions.php"
Now add the below code into the function.php
file:
function new_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','new_admin_account');
We can add username and password with our own choices, we can also set up the user roles for back end access. Just need to change the ‘administrator’ to ‘subscriber’ or ‘contributor’ as per the requirements. Now save the function.php
file and log in with the above user credential. It will works.
Go to the WordPress Dashboard section and click the “Users” menu. Now you can see the new user has been created.
We are hoping this article can give you the best way for how to create new WordPress admin user account via FTP.