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

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