Skip to:
Content
Pages
Categories
Search
Top
Bottom

How do you put the "My Profile" link on the menu?


  • aravindbachu
    Participant

    @aravindbachu

    I have searched high and low for this issue, but found no solution at all.

    I simply want to put a “My Profile/Edit Profile” button in the menu. Thats it.

    I want NO SIDEBAR WIDGETS. A Simple link in the menu.

    Please help.

    Thanks in advance.

Viewing 9 replies - 26 through 34 (of 34 total)

  • Gloopy
    Participant

    @gloopy

    Hi guys i have used the above code but the profile link appears in every menu. How do i add it to just the top menu ?


    ezkay
    Participant

    @ezkay


    khunmax
    Participant

    @khunmax

    Hey Robin

    I installed your snippet as follows:

    // 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
    		$current_user = wp_get_current_user();
    		$user=$current_user->user_login ;
    		$profilelink = '<li><a href="http://www.mysite.com/forums/users/' . $user . '/edit">My Profile/Edit Profile</a></li>';
    		$menu = $menu . $profilelink;
    		return $menu;
    }

    It works perfectly for front end users, however if I am already logged in as the admin and then click on the My Profile link created by your snippet, rather than being redirected to my profile page, I get the “Oops! That page can’t be found” message. The URL that appears in my browser appears correct:

    http://localhost/forum/forums/users/MYUSERNAME/edit

    Any assistance you can provide is greatly appreciated.

    Kind Regards

    Max


    khunmax
    Participant

    @khunmax

    BUMP

    Robin I have installed your OK FINAL ANSWER code listed above and all works as it should with one small BUG.

    If I am logged in as admin and then click on your MY profile link I am not taken to my BBpress front end profile page but rather to an error page:
    ———-
    Oops! That page can’t be found.

    It looks like nothing was found at this location. Maybe try searching?
    ———-
    Can anyone assist me to edit the code so when someone logged in as admin click on the my profile link they are taken to his or her BBpress front end profile.

    Thanks in advance for any assistance you can provide.

    Kind Regards

    Max


    khunmax
    Participant

    @khunmax

    UPDATE and BUMP

    After further testing I have discovered that the error in this code is not due to whether the user is admin or non admin.

    I (admin) have a two word username (blank space in the middle of the two words).

    I created a non admin user account also with a two word user name and get the same error. When that use clicks on the my profile link they are taken to Oops page.

    So in its current form Robins code does not work if the user has a username with more than one word in it.

    Any chance someone can fix this.

    Thanks in advance and kind regards

    Max


    blengine
    Participant

    @blengine

    Another solution for those interested. This makes use of the “Shortcodes in Menus” plugin to easily place the bbpress “View Profile” and “Edit Profile” links in your WordPress nav menus. Instructions:

    1 – Install the free plugin “Shortcodes in Menus”
    2 – Place the following code in your theme’s functions.php file:

    function menu_profile_link() { 
    		$current_user = wp_get_current_user();
    		$profile_menu_item = '<li><a href="' . home_url('forums/users/') . $current_user->user_nicename . '">View Profile</a></li>';
    		return $profile_menu_item;
    }
    add_shortcode('bbp-profile', 'menu_profile_link');
    
    function menu_edit_profile_link() { 
    		$current_user = wp_get_current_user();
    		$profile_menu_item = '<li><a href="' . home_url('forums/users/') . $current_user->user_nicename . '/edit">Edit Profile</a></li>';
    		return $profile_menu_item;
    }
    add_shortcode('bbp-edit-profile', 'menu_edit_profile_link');

    3 – In WordPress go to your Menus and go to the new Shortcodes panel. Type in “View Profile” as the title and underneath that type in [bbp-profile] to place the profile link in your menu. Click “Add to Menu”. Repeat this process using the shortcode [bbp-edit-profile] to add the “Edit Profile” link.

    4 – I’d also recommend the free plug-in “Nav Menu Roles” to restrict your menu items to logged in or logged out users.

    Hope this is useful!


    sarwarc
    Participant

    @sarwarc

    Thanks for finding the solution. Where do I add the code for menu and forum to make the Profile show up in Menu?


    tylertervooren
    Participant

    @tylertervooren

    @sarwarc – I just created this very simple plugin to give you access to the user profile link via a shortcode. You can use it in conjunction with the Shortcodes in Menus plugin to add a link to the user’s profile page in your menu.


    jonmoore
    Participant

    @jonathanmoorebcsorg

    you may not want to add to the end of the menu, I’ve posted an alternative on:

    How Do I link to Profile Page


    to allow a simple link to forums/users/current/ to be replaced with the current user id or redirect to login

Viewing 9 replies - 26 through 34 (of 34 total)
  • You must be logged in to reply to this topic.
Skip to toolbar