Three Easy Ways to Change Your WordPress Username

wordpress username changechange admin usernamewordpress securityupdate wp_userswordpress user management
Published·Modified·

By default, WordPress usernames cannot be modified. However, to improve WordPress security, it is not recommended to use 'admin' as the username. For those who have already set 'admin' as their username, here are three methods to solve this problem.

Method 1: Execute SQL Statement

Log in to phpMyAdmin, select your database, and execute the following SQL statement (replace 'admin' with your original username):

UPDATE wp_users SET user_login = 'NewUsername' WHERE user_login = 'admin';

Executing SQL Statement Figure 1-1: Executing SQL Statement

Method 2: Use functions.php

Add the following code to the functions.php file in your theme directory. This method essentially executes an SQL statement but in a different location. You can delete this code after the username has been changed. Replace 'Current-Username' with your original username and 'New-Username' with your desired new username.

global $wpdb; 
$wpdb->query( "
UPDATE wp_users
SET user_login = 'Current-Username'
WHERE user_login = 'New-Username';
" );

Method 3: Create a New User

This method is relatively simple. You only need to create a new user with any username and assign it administrator privileges in the backend. Then, log in with this new user and delete the original 'admin' user. Some may ask, "What happens to my articles if I delete the admin user?" Don't worry; WordPress will prompt you to transfer the articles to another user, so feel free to delete the old account.

Deleting User Figure 3-1: Deleting User

You can choose any of the three methods that suit you best. If you have any questions, you can contact me via QQ: 337003006.