How to Get in WordPress if You’re Locked Out


For whatever reason, you’ve found yourself locked out of your own site.  Without a user attached to your email address, you can’t even use the Forgot Password feature to get in.  But, you own the site, so surely there must be some way to get in.

Good news, there is!  Better news, it’s easy!

In this post, I’ll show you how to quickly gain access to your WordPress admin area by having access to either the files or the database.

If You Have Access to the Files

This requires knowing the site’s current theme and editing the functions.php  file.  Simply add the following to the bottom of that file:

add_action( 'wp_loaded', function() {
    if( ! username_exists('myadmin') ) {
        $wp_userdata = array(
            'user_login' => 'myadmin',
            'user_pass' => 'test1234!@#$',
            'role' => 'administrator',
        wp_insert_user( $wp_userdata );

Once you’re in go ahead and remove this code since it will be running for every page load unnecessarily.

If You Have Access to the Database

Or, with phpMyAdmin access, you can run these SQL statements…

INSERT INTO `wp_users` (`user_login`, `user_pass`, `user_nicename`, `user_email`, `user_status`)
VALUES ('myadmin', MD5('test1234!@#$'), 'myadmin', '', '0');
INSERT INTO `wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`)
VALUES (NULL, (Select max(id) FROM wp_users), 'wp_capabilities', 'a:1:{s:13:"administrator";s:1:"1";}');
INSERT INTO `wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`)
VALUES (NULL, (Select max(id) FROM wp_users), 'wp_user_level', '10');

Login to Your New Admin Account

Whichever method you chose, you should now be able to login using username: myadmin and password: test1234!@#$ (at least if you used this code without changing it).

Now, time to reset your password to something more secure.

Notify of

Inline Feedbacks
View all comments