Skip to:
Content
Pages
Categories
Search
Top
Bottom

Adding Dynamic Profile Link to Main Menu Item

Viewing 25 replies - 1 through 25 (of 58 total)

  • @mercime
    Participant

    @mercime

    Add this to your theme’s functions.php file
    http://pastebin.com/HSpJNLyV

    Thank you for taking the time mercime.

    Do I need to tweak this code in any way before adding it to the functions.php file.

    Thanks again

    -John


    @mercime
    Participant

    @mercime

    Just make a backup copy of your theme’s functions.php file. That way, if you added the code where you shouldn’t, you can always revert to the original code from your backup.

    Hello Mercime,

    I’m not sure where to add the code in the functions.php. Can I just add it to the bottom of the file?

    I just want to make sure that I explained myself correctly, this time with an example of my actual site.

    I created a page http://impartoo.com/my-profile/ and added a main menu item called “My Profile”.

    What I would like to achieve:
    ā€“>User1 logs in and clicks on http://impartoo.com/my-profile and is redirected to http://impartoo.com/members/user1/profile/

    ā€“>User2 logs in and clicks on http://impartoo.com/my-profile and is redirected to http://impartoo.com/members/user2/profile/

    Thank you for your patience.

    -John


    @mercime
    Participant

    @mercime

    Delete the new page you created since it’s not going to work that way. The code will create a link in the navigation menu for logged in users only and clicking on the link will direct the user to his/her respective profile page.

    == Iā€™m not sure where to add the code in the functions.php. ==

    At the bottom of the functions.php file :
    }
    ?>

    Add code in between:

    }

    // 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 = '

    ' . __('My Profile', 'buddypress' ) . '

     

    ';
    $menu = $menu . $profilelink;
    return $menu;
    }
    ?>


    evolovedesign
    Member

    @evolovedesign

    This post greatly helped me! However I am trying to figure out one other thing, how would you create a sub menu item i.e. a dropdown menu doing it this way? I essentially want to take everything from my admin bar and put it in a dropdown list in my main nav menu


    @mercime
    Participant

    @mercime

    @evolvedesign, please start a new topic next time. There’s a plugin for those using the bp-default or child theme thereof https://wordpress.org/extend/plugins/buddypress-profile-menu/

    Mercime,

    1. I deleted the new page http://impartoo.com/my-profile/, it’s associated menu item “My Profile” was also deleted.
    2. Added the code in functions.php (the file was saved successfully without throwing an error).

    I’m not seeing that the code created a link in the navigation menu when logging in with a user. There is no menu item tab called “My Profile”. Do I need to create a new menu item called “My Profile” in the main navigation menu? If so, how do I do this without creating an associated page?

    Can you please take a look, here is a test user for my site: http://impartoo.com
    username = beenthere
    pass = test

    Thanks again,

    -John

    Do you think I misplaced the code in functions.php ? Please help, I need this resolved.


    @mercime
    Participant

    @mercime

    @wpissues I just tested the code in Custom Community Version 1.8.9.1 from the WP Theme Repo and it’s working fine. Even showed up in both custom menus. If you still haven’t fixed this, post all code you currently have in your functions.php file in pastebin.com


    Thadman
    Participant

    @thadman

    Hi, Mercime, I’m having the same issue with my site. puclpodcast.com/newfinal
    I have pasted my function file in pastebin though so that you may diagnose the problem.
    http://pastebin.com/jXgvLGJB
    Thanks.


    @mercime
    Participant

    @mercime

    @thadman the code won’t work with your theme. You should contact theme developer (or use forums of iblogPro users) who has coded own custom menu and therefore is not using wp_nav_menu function directly to call the menu.


    Thadman
    Participant

    @thadman

    Ok Thanks.
    I am using Custom Community Version 1.8.9.1 though, I’m switching from iBlogPro because I wanted to start using buddypress. The site at the front is an iBlogPro Theme but that function file is from the custom community theme.


    Thadman
    Participant

    @thadman

    http://www.puclpodcast.com/newfinal? Is a custom community theme and that function file does have a a call for wp_nav_menu.


    @mercime
    Participant

    @mercime

    @thadman as I mentioned above, the code works in Custom Community theme per my test.

    Posted in pastebin.com => functions.php file of Custom Community with the dynamic profile link at the bottom of the file. http://pastebin.com/cagpd9Mc

    @mercime, thanks again for following up on this.

    I pasted my functions.php code in pastebin.com , saved as “DynamicProfile-061812”

    http://pastebin.com/QeviFwHG

    for the time being I installed the following plugin “BuddyPress login redirect” to partially solve my issue. This plugin redirects the user to their personal profile page but I still need the menu item to appear as well.

    -John

    So glad I cam across this code edit for “my profile” added to the menu. My only question is how would I get this menu item moved to the first spot instead of the last spot.
    Thank you

    @mercime is there a code to move the new “my profile” menu item to the first position (to the right of “home”)?


    cpinsd
    Participant

    @cpinsd

    I have two navigation menus, is there a way to specify which navigation menu it goes to and is there a way to place in front?


    @mercime
    Participant

    @mercime

    @kissandim didn’t get the notification. Just in case you haven’t found the solution yet, just move $profilelink before the $menu, therefore the last three lines should look like this:

    $menu = $profilelink . $menu;
    return $menu;
    }

    @cpinsd if you have more than one custom menu in your theme, find out the ‘theme_location’=>’???’ of that specific wp_nav_menu. For example, the location is mamamia then the code would be

    // Filter wp_nav_menu() to add profile link in a specific custom menu e.g. mamamia
    function mme_nav_menu_profile_link($menu, $args) {
        if( is_user_logged_in() && $args->theme_location == 'mamamia' ){
            $profilelink = '<li><a href="' . bp_loggedin_user_domain( '/' ) . '">' . __('My Profile', 'yourtheme') . '</a></li>';
            $menu = $menu . $profilelink;
        }
        return $menu;
    }
    add_filter( 'wp_nav_menu_items', 'mme_nav_menu_profile_links', 10, 2 );

    modemlooper
    Moderator

    @modemlooper

    since this is such a requested feature i’ll update the plugin to work with other them locations besides bp-defaults


    @mercime
    Participant

    @mercime

    Thank you @modemlooper I’m sure many users will be delighted by the addition :-)

    @mercime that is almost what I need, but now it is before the “home” link. i’d like to move it to the second location directly to the right of home. Thank you in advance for your help

    @mercime forget it, I figured out a way around it!Thanks for all your help!!


    @mercime
    Participant

    @mercime

    @kissandim you’re welcome. glad you resolved it on your own :-)

Viewing 25 replies - 1 through 25 (of 58 total)
  • The topic ‘Adding Dynamic Profile Link to Main Menu Item’ is closed to new replies.
Skip to toolbar