Create new Admin account in WordPress via Function.php File

Markadler

New member
Joined
Jun 14, 2016
Messages
17
Points
0
If you're using Wordpress on a shared or a VPS to run your websites, but for some reasons, you forgot your Admin password and you could not login to WP admin page.

Following these instructions to create an Admin account via function.php file in your theme folder.

Step 1:

In the file manager of your hosting, access to theme folder that you are using.

For example, you are using wordpress theme called: mytheme then the path we need to use is:

/wp-content/themes/mytheme/function.php

Step 2:

Edit function.php file and insert the following code

(Insert after tag the <?php)
Code:
function add_admin_acct(){
	$login = 'username';
	$passw = 'yourpassword';
	$email = 'youremailaddress;

	if ( !username_exists( $login )  && !email_exists( $email ) ) {
		$user_id = wp_create_user( $login, $passw, $email );
		$user = new WP_User( $user_id );
		$user->set_role( 'administrator' );
	}
}
add_action('init','add_admin_acct');
username: you want to create a new admin username

yourpassword: it's your password

youremailaddress: Email of admin account

Step 3:

Save the file, access the login page on your Wordpress site, example.com/wp-admin/ and login with your new account just created

Good luck!
 

Ron Killian

New member
Joined
Dec 3, 2015
Messages
804
Points
0
I just change the password in the database using phpMyAdmin. Seems much easier that adding code and all that. Plus code that hackers might get in with/into?
 

Eoon

New member
Joined
Mar 18, 2013
Messages
35
Points
0
Eoon
It also a good way to get the password back.

In my personal opinion, from code's the OP, it could be use to get a new admin account and we can use this way temporarily, after got the account, we should delete codes for more secure.
 

JonaHost

New member
Joined
Jun 28, 2016
Messages
21
Points
0
This code has been widely used in cases where client remove developer and take over website without paying.
If your own the wordpress website, its quite simple to do a password reset.
 
Latest threads
Replies
0
Views
29
Replies
0
Views
31
Replies
1
Views
41
Replies
3
Views
106
Recommended threads
Replies
4
Views
2,086
Replies
1
Views
2,757
Replies
20
Views
10,696
Replies
4
Views
2,331
Top