Run Username SQL Query from WordPress Child Theme Functions File


Having an admin account, I can change everything except the username (which happens to be the login name). I am therefore wondering how to change the username using the functions file.

Running the below as a SQL query works fine, but how do I “convert” it into a function?

function username_query() {
    global $wpdb;
    $result = (UPDATE `wp_users` SET `user_login`= 'new-admin-name-here' WHERE `user_login`='old-admin-name-here');


Any help is appreciated and yes; I know that the user will be logged out and asked to login again.

, Moa Andersen 4 years 2020-07-21T00:10:46-05:00 0 Answers 52 views 0

Leave an answer