Wordpress Change Default Display Name Publicy As for all existing users

前端 未结 6 609
耶瑟儿~
耶瑟儿~ 2021-02-05 23:58

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

6条回答
  •  灰色年华
    2021-02-06 00:33

    Quick and dirty hack would be to edit the file 'wp-includes/user.php' edit the folowing

    if ( empty($display_name) )
        $display_name = $user_login;
        $display_name = apply_filters('pre_user_display_name', $display_name);
    

    Edit this line

    $display_name = $user_login;
    

    Change to:

    $display_name = $first_name . ' ' . $last_name;
    

    The above solution should work, assuming that the user.php file isn't changed in a WordPress update or alternativly you could add something like this to your functions.php

    //force display-name of users to Firstname Lastname
    add_action('admin_head','force_pretty_displaynames');
    function force_pretty_displaynames() {
        $current_user = wp_get_current_user();
        if ($current_user->display_name != $current_user->first_name." ".$current_user->last_name){ 
           update_user_meta($current_user->ID, 'display_name', $current_user->first_name." ".$current_user->last_name);
        }
    
    }
    

    but agian a few checks on this above could be added to see if the user is logged in, is an admin, contributor etc..etc..

    but should do what your looking for..

    Source: http://wordpress.org/support/topic/change-default-display-name-1

    Marty

提交回复
热议问题