Three Easy Methods to Modify WordPress Usernames

Publish: 2014-11-11 | Modify: 2014-11-11

By default, WordPress usernames cannot be changed. However, for security reasons, it is not recommended to use "admin" as the username. If you have already used "admin" as your username and want to change it, here are three methods to solve this problem.

Method 1: Execute SQL Statement

Login to phpMyAdmin and execute the following SQL statement in your database (replace "admin" with your original username and "new-username" with your desired new username):

UPDATE wp_users SET user_login = 'new-username' WHERE user_login = 'admin';

Method 2: Use functions.php

Add the following code to the functions.php file in your theme directory. This method is essentially executing an SQL statement, but in a different location. Once the username is changed, you can delete this code. 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: Add a New User

This method is relatively simple. Simply add a new user with any username of your choice and grant it administrator privileges. Then, log in with this new user and delete the previous user with the username "admin". WordPress will prompt you to transfer the posts to another user before deleting the "admin" user.

You can choose any of the above methods that you find most suitable. If you have any questions, you can add me on QQ at 337003006.


Comments