user_nicename has the same value with user_login. I want to change user_nicename value only by using code snippet into functions.php or wp-config.php. Is it possible without using phpmyadmin or any plugin?
user_nicename has the same value with user_login. I want to change user_nicename value only by using code snippet into functions.php or wp-config.php. Is it possible without using phpmyadmin or any plugin?
Share Improve this question edited Dec 13, 2018 at 2:53 Tom J Nowell♦ 61.2k7 gold badges79 silver badges150 bronze badges asked Dec 13, 2018 at 1:22 Serdar KoçakSerdar Koçak 522 silver badges7 bronze badges 7 | Show 2 more comments1 Answer
Reset to default 6Yes, you can use wp_update_user()
:
wp_update_user( array(
'ID' => 123,
'user_nicename' => 'value'
) );
Just replace 123
with the proper user ID, and value
with the preferred user_nicename
value.
The function also enables you to change the value of other fields in the WordPress users table (wp_users
).
user_nicename
anduser_login
are separate for a reason, and they aren't the same.user_nicename
is the URL sanitized version ofuser_login
, changing it to something else might break things in unexpected ways. Perhaps you actually wanted to changedisplay_name
? – Tom J Nowell ♦ Commented Dec 13, 2018 at 2:53user_nicename
exists is because if you have an umlaut or other non-URL friendly character in your username, it wouldn't match when you did the query, so it sanitises it ahead of time for performance – Tom J Nowell ♦ Commented Dec 14, 2018 at 14:35