Skip to:
Content
Pages
Categories
Search
Top
Bottom

How to add user profile link to specific menu?

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

    Participant

    @dayan89 – with one of my bp installs I can go to appearance -> menus.. select main-menu (or topmenu, or whatever you called the one you want on top) – click select.. then on the left side I had a tab for buddypress.. with cool links for dynamic links like “my profile” – login.. etc..

    click to add to your menu, save..
    easy now these days..

    for some reason I don’t have that tab under menus on my other bp install – so your setup may vary.

    @danbp

    Participant

    Hi @djsteveb,
    I don’t have that tab under menus on my other bp install Really ? Have you activated buddypress in screen options ? Just in case of… 😉

    BuddyPress Links in WordPress Menus

    @danbp

    Participant

    @dayan89,

    could it be that you created your Top menu, by adding a new menu without having two different menu location in your theme ? This can explain why you see always your item, what ever menu you choose. This happen because you try to assign 2 different menus to a same place.

    Following snippets where successfully tested with Twenty Twelve.

    This fires the profile link on the menu tab.

    function profile_button_menu_item ( $items, $args ) {
       
    // menu name. Primary is default main menu location in Twenty themes
        if ( $args->theme_location == 'primary') {
            $items .= '<li><a href="' . bp_loggedin_user_domain() . 'profile/public/">' . __('My Profile') . '</a></li>';
        }
        return $items;
    }
    add_filter( 'wp_nav_menu_items', 'profile_button_menu_item', 10, 2 );

    The following explains how it works with 2012.

    In 2012’s header.php, there is only one menu, located line 45
    <?php wp_nav_menu( array( 'theme_location' => 'primary', 'menu_class' => 'nav-menu' ) );?>

    To use 2 menus, I added below that line another location
    <?php wp_nav_menu( array( 'theme_location' => 'top', 'menu_class' => 'nav-menu' ) );?>

    In child-theme’s functions.php, i added

    
    function register_my_menu() {
      register_nav_menus(
        array(
          'top' => 'Top'   
        )
      );
    }
    add_action( 'init', 'register_my_menu' );

    Under Menu Settings (wp-admin/nav-menus.php) i have now 2 theme locations.
    Primary Menu and Top
    Understand here that 2 locations are different of having only 2 menus. Location is a unique place for ONE menu.

    Of course, I have 2 different menus. One is assigned to Primary Menu location, the other one to Top location.

    And i can now move my profile item from one to other menu, by simply changing the location (primary ⇔ top) in profile_button_menu_item function.

    Codex reference: https://codex.wordpress.org/Navigation_Menus

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to add user profile link to specific menu?’ is closed to new replies.
Skip to toolbar