Set “Display name publicly as” to be usernames by default

My WordPress site currently displays users’ identifying information by their FIRSTNAME + LASTNAME.

The vast majority prefer to be known by their usernames. I’ve instructed how to change their “Display Name Publicly As” manually (i.e. via their User settings) but this is less than ideal.

I would like new users to be shown by their usernames as the default. Note that I want this to reflect in several plugins that refer to the “Display Name Publicly As” property.

How can this be done?

2 Answers
2

If you want this for all future users then hook into the user_register event and update it there.

Pull the WP_User using get_userdata and wp_update_user info with the new display name.

add_action( 'user_register', 'wpse_20160110_user_register', 10, 1 );

function wpse_20160110_user_register ( $user_id ) {

    // get the user data

    $user_info = get_userdata( $user_id );

    // pick our default display name

    $display_publicly_as = $user_info->user_login;

    // update the display name

    wp_update_user( array ('ID' => $user_id, 'display_name' =>  $display_publicly_as));
}

If you want to set this every login then hook wp_login using PHP_INT_MAX.

function wpse_20160110_wp_login ( $user_login, $user ) {

    wp_update_user(array('ID' => $user->ID, 'display_name' => $user_login));

}

add_action('wp_login', 'wpse_20160110_wp_login', PHP_INT_MAX, 2);

Leave a Comment