php

Manually Add a WordPress Admin User via FTP & Functions.php

7/25/2025
5 min read

Creates a new WordPress admin user manually via functions.php. Useful when locked out of the dashboard. Remove the code after login to prevent unauthorized access.

Tips:

  • Replace 'Username', 'Password', and 'email@domain.com' with your desired credentials.

  • After the admin is created, remove this code from functions.php to avoid security risks.


function wpb_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', 'wpb_admin_account' );