Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have created a custom menu item that creates a link to the users buddypress profile page, but it adds the link at the end of the logged in users menu.

<nav>
<ul>                
<li><a href="#">My Account</a>
    <ul class="sub-menu">
      <li>Other account links here.</li>
    </ul>
</li>    
<li><a href="#">My Profile</a></li>
</ul>               
</nav>

What I'd like to to is add it to the "My Account" sub-menu.

<nav>
<ul>                
<li><a href="#">My Account</a>
    <ul class="sub-menu">
      <li>Other account links here.</li>
      <li><a href="#">My Profile</a></li>
    </ul>
</li>    
</ul>               
</nav>

This is the code I've used to create the menu item, but I can't figure out how to get add it to this particular sub-menu instead of right at the end of the whole menu.

// Filter wp_nav_menu() to add profile link
add_filter( 'wp_nav_menu_items', 'my_nav_menu_profile_link' );
function my_nav_menu_profile_link($menu) {  
    if (!is_user_logged_in())
    return $menu;
else
    $profilelink = '<li><a href="' . bp_loggedin_user_domain( '/' ) . '">' . __('My Profile') . '</a></li>';
    $menu = $menu . $profilelink;
    return $menu;
}

Any suggestions greatly appreciated!

share|improve this question
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.