BuddyPress avatar & notifications in menu

Hi,
Could you tell us how to implement the BuddyPress avatar & notifications in the menu? we've seen a few plugins around, however we're unable to integrate them into the menu :disappointed:
This is what we're looking for:

Or:

Thanks in advance!

  • Nithin

    Hi M.,

    Hope you are doing good today. :slight_smile:

    I couldn't find any plugin that offers such out of the box setting feature in the plugin, it would require custom coding to achieve such a similar setup. Please check whether the following thread helps:
    https://buddypress.org/support/topic/bp-custom-menu-help/

    To include an avatar along the menu, you could try the following code, which should provide you with an outline:

    <?php
            global $current_user;
            get_currentuserinfo();
            echo get_avatar( $current_user->ID, 64 );
     ?>

    I hope this should help in getting your started. Have a nice day. :slight_smile:

    Kind Regards,
    Nithin

  • Rupok

    Hi M.,

    Sorry for the confusion. The code Nithin provided will display the avatar for the currently logged in user. So you should be putting that in some places on your template files, so it displays the output.

    Let me add more details. Suppose, you want to show the user avatar beside your menu. So you should find the file generating your menu in your theme folder. Most of the times, it's in "header.php". So you should be adding those lines just after the lines generating your menu.

    However, a better approach will be using a filter. So you should be adding the following lines in your theme's function.php file:

    add_filter( 'wp_nav_menu_items', 'show_avatar_in_menu', 10, 2 );
    function show_avatar_in_menu ( $items, $args ) {
    
        global $current_user;
        get_currentuserinfo();
    
        if ($args->theme_location == 'primary') {
            $items .= '<li>'.get_avatar( $current_user->ID, 64 ).'</li>';
        }
        return $items;
    }

    That will add your avatar in your menu.

    Please note, adding code in the functions.php file is not a better way because changes will be gone with theme update.

    Best way will be doing this with a MU Plugin. For creating a MU Plugin, create a folder named "mu-plugins" inside your "wp-content" folder. Then inside that "mu-plugins" folder, create a file with any name and with a .php extension. Now paste the code inside that file and save.

    <?php
    add_filter( 'wp_nav_menu_items', 'show_avatar_in_menu', 10, 2 );
    function show_avatar_in_menu ( $items, $args ) {
    
        global $current_user;
        get_currentuserinfo();
    
        if ($args->theme_location == 'primary') {
            $items .= '<li>'.get_avatar( $current_user->ID, 64 ).'</li>';
        }
        return $items;
    }

    For getting more idea on mu plugins, you can go through this article: http://premium.wpmudev.org/manuals/wpmu-manual-2/using-mu-plugins/

    For showing Notification Count in the menu, can you please try the solution provided here? https://buddypress.org/support/search/notifications+counter/

    I believe, these will help.

    Please let us know if you have any confusion or if you have any further query. We will be glad to help.

    Have a nice day. Cheers!
    Rupok

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.