• Resolved notthisagain

    (@notthisagain)


    Hello,

    I am trying to get it so that customer’s first name’s are displayed rather than their username (which is often an email or a combination of their first and last name). Would this be possible?

    Many thanks and warm regards,

    Joao

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support Muhammad Arslan

    (@wparslan)

    Hey,

    We have created a filter hook for this. If you want to change the username which is showing in the navigation.

    You can modify the given code accordingly.

    Helping Documentation: https://loginpress.pro/doc/login-logout-menu-filters/

    /**
    
    * Filter to Change the user profile link text
    
    *
    
    * @param [String] $user_name The name of the user who is logged in
    
    *
    
    * @return [string] Custom String and the username
    
    */
    
    add_filter( 'login_logout_menu_username', 'custom_loginpress_login_logout_menu_username' );
    
    function custom_loginpress_login_logout_menu_username( $user_name ) {
    
    $current_user = null !== wp_get_current_user() && ! empty( wp_get_current_user() ) ? wp_get_current_user()->display_name : $user_name;
    
    return $current_user;
    
    }

    Kindly copy and paste the following in your theme’s functions.php file.

    This code will modify the username to display name.

    Have a nice day!

    Thread Starter notthisagain

    (@notthisagain)

    Thank you for your prompt response!

    I have tried that but that displays the display name as the username. I was wondering if it would instead be possible to display the first name (instead of the username or display name).

    Many thanks and warm regards,

    Joao

    Plugin Support Muhammad Arslan

    (@wparslan)

    Hey @notthisagain

    Kindly replace the following piece of code with the old one.

    This following code will look for the first name and will show it, It will also look for the last name as well and if found it will attach that as well.

    If first and last name are not found, then it will show the display name:

    /**
    
    * Filter to Change the user profile link text
    
    *
    
    * @param [String] $user_name The name of the user who is logged in
    
    *
    
    * @return [string] First and last name accordingly.
    
    */
    
    add_filter( 'login_logout_menu_username', 'custom_loginpress_login_logout_menu_username' );
    
    function custom_loginpress_login_logout_menu_username( $user_name ) {
    
    $user_id = null !== wp_get_current_user() && ! empty( wp_get_current_user() ) ? wp_get_current_user()->ID : '';
    
    if ( empty( $user_id ) ) {
    
    return $user_name;
    
    }
    
    $user_info = $user_id ? new WP_User( $user_id ) : wp_get_current_user();
    
    if ( $user_info->first_name ) {
    
    if ( $user_info->last_name ) {
    
    return $user_info->first_name . ' ' . $user_info->last_name;
    
    }
    
    return $user_info->first_name;
    
    }
    
    return $user_info->display_name;
    
    }

    Have a nice day!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Change display username to display first name’ is closed to new replies.