Small issue... I'd like my users display name to always

Hi guys,-
Small issue...
I'd like my users display name to always be:
"firstname"space"lastname" ALWAYS...!!

How to best and easyest acomplish that....??

Thanks in advance
Per

  • Michael Bissett

    Hey @Per, hope you're doing well today! :slight_smile:

    As long as a user has a first & last name entered, you should be able to use this PHP code snippet, inserted as a mu-plugin, to do the job:

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

    (Courtesy of aubreypwd.com)

    Let me know if this helps please! :slight_smile:

    Kind Regards,
    Michael

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.