does anyone know of way I can change the existing display name publicly as for all users. I want to have firstname lastname as the default because this will reflect in the forum. I have read all the forums and have tried all the hacks, any suggestions would be appreciated. Thanks in advance
The Default – Display name publicly as field only appears on the Edit Profile Page. Inside the field options you can set the field title, description and default value. Also you can set it be Required or not.
You can change both your WordPress.com account username (the name you use to login) and your display name (the name that is seen on your posts and comments).
To actually change WordPress usernames, you'll need to press Update for the specific user you want to edit. Next, write your New Username and choose if you want to send an email notification about the changes just made. Then press Update Username and that's it, you are good to go.
To get a WordPress user's display name, you need to get the user object, then use $user->display_name to access the user's name. If the user hasn't specifically set anything as their display name, it will default to their username. So you don't have to worry about fallbacks.
Here's an improved version of richplane's answer that works in newer versions of WordPress (3.8+):
/**
* Format WordPress User's "Display Name" to Full Name on Login
* ------------------------------------------------------------------------------
*/
add_action( 'wp_login', 'wpse_9326315_format_user_display_name_on_login' );
function wpse_9326315_format_user_display_name_on_login( $username ) {
$user = get_user_by( 'login', $username );
$first_name = get_user_meta( $user->ID, 'first_name', true );
$last_name = get_user_meta( $user->ID, 'last_name', true );
$full_name = trim( $first_name . ' ' . $last_name );
if ( ! empty( $full_name ) && ( $user->data->display_name != $full_name ) ) {
$userdata = array(
'ID' => $user->ID,
'display_name' => $full_name,
);
wp_update_user( $userdata );
}
}
Problem with using the admin_head hook is that it doesn't work for users who don't use the admin system. Also, my attempts to implement the solution posted by Marty failed because it doesn't seem that the display_name can be updated by update_user_meta() - you have to use wp_update_user().
My proposal - put this in your functions.php file:
function force_pretty_displaynames($user_login, $user) {
$outcome = trim(get_user_meta($user->ID, 'first_name', true) . " " . get_user_meta($user->ID, 'last_name', true));
if (!empty($outcome) && ($user->data->display_name!=$outcome)) {
wp_update_user( array ('ID' => $user->ID, 'display_name' => $outcome));
}
}
add_action('wp_login','force_pretty_displaynames',10,2);
For me (using WP 3.4.1), that works OK, replacing the display name as soon as they log in.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With