I am using buddypress username only plugin which works fine everywhere else except dwqa section. How do i change the user’s dispay name to his unique username on my website ?
Hi,
About this issue, you can change in the Dashboard > User > Display name publicly as select-box, you can select the First name or last name that you want to display for user.
Or you can add the following code to the functions.php
file:
- Sets the user’s display name (always) to first name last name, when it’s avail.
add_action ('admin_head','make_display_name_f_name_last_name');
function make_display_name_f_name_last_name(){
$users = get_users(array('fields'=>'all'));
foreach($users as $user){
$user = get_userdata($user->ID);
$display_name = $user->first_name . " " . $user->last_name;
if($display_name!=' ') wp_update_user( array ('ID' => $user->ID, 'display_name' => $display_name) );
else wp_update_user( array ('ID' => $user->ID, 'display_name' => $user->display_login) );
if($user->display_name == '')
wp_update_user( array ('ID' => $user->ID, 'display_name' => $user->display_login) );
}
}
- Sets the user’s display name (always) to first name, when it’s avail.
add_action ('admin_head','make_display_name_f_name_last_name');
function make_display_name_f_name_last_name(){
$users = get_users(array('fields'=>'all'));
foreach($users as $user){
$user = get_userdata($user->ID);
$display_name = $user->first_name;
if($display_name!=' ') wp_update_user( array ('ID' => $user->ID, 'display_name' => $display_name) );
else wp_update_user( array ('ID' => $user->ID, 'display_name' => $user->display_login) );
if($user->display_name == '')
wp_update_user( array ('ID' => $user->ID, 'display_name' => $user->display_login) );
}
}
- Sets the user’s display name (always) to last name, when it’s avail.
add_action ('admin_head','make_display_name_f_name_last_name');
function make_display_name_f_name_last_name(){
$users = get_users(array('fields'=>'all'));
foreach($users as $user){
$user = get_userdata($user->ID);
$display_name = $user->last_name;
if($display_name!=' ') wp_update_user( array ('ID' => $user->ID, 'display_name' => $display_name) );
else wp_update_user( array ('ID' => $user->ID, 'display_name' => $user->display_login) );
if($user->display_name == '')
wp_update_user( array ('ID' => $user->ID, 'display_name' => $user->display_login) );
}
}
Hope this helps !
I want to have the username as default instead of the first name / last name.
Eg – @xyz is the username used by a user while signing up apart from his her full name.
At the moment, our plugin does not support to display author name like that, unfortunately.
Is this still not supported? Or is there an updated code to add to functions.php?
Yes, you can try this solution, you can add the code to the functions.php file.
If you have any issue or question, you can let me know. We will check and help you resolve it.
Hello, thanks for the answer. I was wondering if the show “Username” as default display name is supported?
At the moment, the plugin will show the username. If you want to show the last name, first name or the full name you can use the code that we have provided in this question.
Please login or Register to submit your answer