Navigation
This is archived content. Visit our new forum.
  • Author
    Posts
  • #153277

    Gatera
    Participant

    Hi,

    I wanted to display the user’s username in the navigation menu when they are logged in. I found a few solutions but they do not work perfectly.

    First I used this function bp_loggedin_user_id() and it displays the ID number nicely, with no problem. However since what I need is the name I went on to use bp_get_displayed_user_fullname()

    When I am on the profile page, the user’s name displays nicely, but when I navigate to another page, nothing shows.

    #153501

    Friech
    Moderator

    Hi there.

    Thanks for writing in! To assist you with this issue, we’ll first need you to provide us with your URL as stated on the forum entrance page. This is to ensure that we can provide you with a tailored answer to your situation. Once you have provided us with your URL, we will be happy to assist you with everything.

    Cheers.

    #153788

    Gatera
    Participant

    Hi,

    I am currently still mainly working on my localhost, however I have a demo site up at village.rw

    #154120

    John Ezra
    Member

    Hi there,

    Does your demo have the same setup as you local? Also note since this has to do with a 3rd Party plugin, depending on what we find, we may or may not be able to support the issue.

    Would you mind providing us with login credentials so we can take a closer look? To do this, you can make a post with the following info:

    – Link to your site
    – WordPress Admin username / password
    – FTP credentials

    Don’t forget to select Set as private reply. This ensures your information is only visible to our staff.

    #154447

    Gatera
    Participant

    Hi,

    No. The demo does not have the set up am currently inquiring about. I found how to display the name. I put the following code in my functions.php and it works great.

    add_filter( 'wp_nav_menu_items', 'my_custom_menu_item');
    
    function my_custom_menu_item($items)
    {
        if(is_user_logged_in())
        {
            $user=wp_get_current_user();
            $name=$user->user_firstname; // or user_login , display_name, user_lastname
            $ppicture=$user->bp_displayed_user_avatar;
            $items .= '<li>' .$ppicture;
            $items .= '<li><a href="' . bp_loggedin_user_domain( '/' ) . '">'.$name.'</a>';
        }
        return $items;
    }

    However I am now trying to get the buddypress profile picture to show up too. I’ve run into the same issue once again. when I use the function bp_displayed_user_avatar(); the picture only shows when I am on my profile. When I navigate elsewhere it doesn’t show. I am thinking there has to be some code in the profile page that enables the function to return a result. And that code is missing on other pages which is why it returns empty. But I don’t know what it is exactly.

    Kind regards

    Vital

    #154860

    Rad
    Moderator

    Hi Gatera,

    How about this one?

    add_filter( 'wp_nav_menu_items', 'my_custom_menu_item');
    
    function my_custom_menu_item($items)
    {
        if(is_user_logged_in())
        {
            $user=wp_get_current_user();
            $name=$user->user_firstname; // or user_login , display_name, user_lastname
    
    ob_start();
    bp_displayed_user_avatar( 'type=full' );  
    $ppicture= ob_get_clean();
    
            $items .= '<li>' .$ppicture;
            $items .= '<li><a href="' . bp_loggedin_user_domain( '/' ) . '">'.$name.'</a>';
        }
        return $items;
    }

    Hope this helps.

    #155632

    Gatera
    Participant

    Hi,

    Thanks for the help. It works even better than what I had. However there is still the issue of it only showing when am on the profile page. When on another page nothing shows.

    #155751

    Kosher K
    Member

    Hi There,

    Can you put your local set-up to your online demo and provide us with wordpress and FTP access of that site?

    Its hard to check on your issue if we can’t check the actual set-up you have.

    Thanks