WordPress Change Default Display Name Publicy As for all existing users

<?php

//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) );
    }
}

?>

From: WordPress Change Default Display Name Publicy As for all existing users

4 thoughts on “WordPress Change Default Display Name Publicy As for all existing users”

  1. I’m using the S2Member List function and needed this in order to sort properly by last name. Just what I’ve been looking for. THANKS!!!!

Leave a Reply