amelierosalyn

Skip navigation

1 post from April 2008

How to change your WordPress username

Sick of using the name 'admin' to login to your WP installation? Have a user with the login 'PiNkbUnNiEz!1" but want to change it without that user losing all their posts/creating a new account etc.? Tried to do it but found the field disabled in your WP admin panel?
Here is what you need to do.

  1. Before you do anything, backup your database. If you don't know how to do this, ask at the WP forums or Google it - there are some plugins that will do this for you if you don't have access to things like phpMyAdmin (a MySQL tool which can be used to backup your database - Jem has a tutorial on this which may be useful)

  2. Paste this into a file. Name it anything you like, as long as it has a .php extension:

    <?php
    $existing_username = 'admin';
    $new_username = 'MY_NEW_USERNAME';

    // —————

    if (!file_exists('wp-config.php')) exit('Could not find wp-config.php, please make sure you place this file in the same directory as all your WP files.');

    require 'wp-config.php';

    $link = @mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD);
    if (!$link) exit('Could not connect to MySQL');
    mysqli_select_db($link, DB_NAME) or exit('Could not connect to MySQL');

    if (mysqli_query($link, 'UPDATE `' . $table_prefix . "users` SET `user_login` = '" . mysqli_real_escape_string($link, $new_username) . "' WHERE `user_login` = '" . mysqli_real_escape_string($link, $existing_username) . "' LIMIT 1")) echo 'Username updated, your username is now ' . $new_username . '.';
    else echo 'Could not update your username. MySQL said: ' . mysqli_error($link);

    mysqli_close($link);
    ?>

    Change the first two lines (excluding the one that says '<?php', obviously :P ) to your existing username (probably admin) and your new desired username. Save the file, then upload it to your WordPress directory. Make sure this file is in the same place as wp-config.php.

  3. Go to the file in your browser, e.g. yoursite/wordpress/the-file.php and voilà! :D