Skip to:
Content
Pages
Categories
Search
Top
Bottom

Buddypress Avatar in Nav Menu

  • @messina82

    Participant

    Hi All, i’m been looking like crazy to find a solution but have yet to come by it. I’ve created a custom menu in wordpress and placed it in a widget which is essentially my 3rd nav bar. I would like for it to display the user avatar when a user is logged in as the first or second list item in the menu. Anyone have a clue?

    Any help would be much appreciated!

Viewing 3 replies - 1 through 3 (of 3 total)
  • @sammjv

    Participant

    Hi
    Copy avatar code from,
    Members -> single -> profile.php
    Or from
    Member->single -> header.php

    <div id="item-header-avatar">
    	<a href="<?php bp_displayed_user_link(); ?>">
    
    		<?php bp_displayed_user_avatar( 'type=full' ); ?>
    
    	</a>
    </div><!-- #item-header-avatar -->

    Paste and adjust where ever you want.
    But keep in mind by copying ull get two profile pic, so either reduce the size through css or directly cut the code.
    I think first one is better
    Hope this u got the soln

    @shanebp

    Moderator

    bp_displayed_user_link() and bp_displayed_user_avatar only work on a profile page.

    Instead use: bp_loggedin_user_domain() and bp_loggedin_user_avatar().

    @messina82

    Participant

    Thank you very much all. I’ve been able to add the profile image to users logged in but for some reason it strips all the code around it. The avatar as well as the other links are part of a unordered list. This is the code i’m working with:

    // Filter wp_nav_menu() to add profile link in a specific custom menu
    function member_links($menu, $args) {
        if( is_user_logged_in() && $args->theme_location == 'membermenu' ){
        	$profilelink = '<li class="bp-menu bp-activity-nav menu-item menu-item-type-custom menu-item-object-custom"><a href="' . bp_loggedin_user_domain( '/' ) . '">' . __('My Profile') . '</a></li>';
            $profileimage = '<li class="bp-menu bp-activity-nav menu-item menu-item-type-custom menu-item-object-custom"><a href="' . bp_loggedin_user_domain( '/' ) . '">' . bp_loggedin_user_avatar() . '</a></li>';
            $menu = $profilelink . $profileimage . $menu;
        }
        else {
    
         if( !is_user_logged_in() && $args->theme_location == 'membermenu' ){
            $profilelink = '<li class="bp-menu bp-activity-nav menu-item menu-item-type-custom menu-item-object-custom"><a href="' . bp_loggedin_user_domain( '/' ) . '">' . __('Test') . '</a></li>';
            $menu = $profilelink . $menu;
        }
    }
        return $menu;
    }
    add_filter( 'wp_nav_menu_items', 'member_links', 10, 2 );
    
    //Member Menu
    function buddy_navigation () {
      echo '<div class="member-menu-container">';
    	$args = array(
    			'theme_location'  => 'membermenu',
    			'container'       => 'nav',
    			'container_class' => 'wrap',
    			'menu_class'      => 'menu genesis-nav-menu member-menu',
    			'depth'           => 1,
    		);
    	wp_nav_menu( $args );
      echo '</div>';
    }
    
    add_theme_support ( 'genesis-menus' , array ( 'primary' => 'Primary Navigation Menu' , 'secondary' => 'Secondary Navigation Menu' ,'membermenu' => 'Member Menu' ) );
    
    add_shortcode('buddynav', 'buddy_navigation');
    

    Essentially i’m creating the buddy navigation, outputting it as a shortcode and throwing it in a widget followed by appending the additional links above.

    Any idea what’s going on here? Also if i were to integrate specific admin links, would I add another else / if statement targeted to is_admin?

    Thanks for the help!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Buddypress Avatar in Nav Menu’ is closed to new replies.
Skip to toolbar