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 25 replies - 1 through 25 (of 34 total)

  • Robin W
    Moderator

    @robin-w

    I am still playing with this, and it doesn’t currently work, but it’s something like adding the following to your functions file

    // 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="<?php bbp_user_profile_url( bbp_get_current_user_id() ); edit" >Amend Profile</a></li>';
    		$menu = $menu . $profilelink;
    		return $menu;
    }

    Syntax needs sorting

    I’m out most of today, but if you or someone else cracks this, then paste the solution here, and it’ll save me repeating the work.

    Solution is based on

    https://buddypress.org/support/topic/adding-dynamic-profile-link-to-main-menu-item/

    which does the business for buddypress.


    aravindbachu
    Participant

    @aravindbachu

    I just don’t understand how WordPress.org manages to have a “view your profile” button in its support forums which are said to be bbpress forums.


    Robin W
    Moderator

    @robin-w

    your last question is easy, .org have customised, just as you are trying to do by adding it as a menu item – we all like it to look slightly differently to others.

    I have tried from my little knowledge to get it to work but can’t. The best I can get is

    // 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
    		$user      = get_userdata( $user_id );
    		$name      = esc_attr( $user_name );
    		$user_link = '<li><a href="http://www.mysite.com/forums/users/' . $user . '/edit">Amend profile</a></li>';
    		$menu = $menu . $user_link;
    		return $menu;
    }

    But this just returns

    http://www.mysite.com/forums/users//edit

    Sorry, I have given up.

    Can someone else get this working? – it is now annoying me !


    aravindbachu
    Participant

    @aravindbachu

    Simply too frustrating. I believe I am going to quit bbpress now. I am just unable to get a bloody “edit my profile” link in the menu!!

    I am surprised that such a small function isn’t provided in bbpress.

    bbpress sucks. badly.


    Robin W
    Moderator

    @robin-w

    I’m sorry that you feel that something for which you paid nothing isn’t for you.

    But I don’t think that abusing the people on here who are trying to help you by saying it sucks is really the way forward.

    I hope you are able to find some free software that works precisely as you want.

    Whilst most people use sidebars and widgets to perform these functions, I shall continue to see if there is an easy way to get this into a menu and add it to the codex if I work it out.

    Best wishes

    Robin


    Robin W
    Moderator

    @robin-w

    the best solution so far courtesy of Ronthai

    In Dashboard>plugins>add new
    Search for WP exec PHP, install and activate

    Create a new page called “profile” or whatever name you want

    In content of this page, add this code

    <meta http-equiv="refresh" content="0;URL=http://mysite.com/forums/users/<?php global $current_user;
          get_currentuserinfo();
    
         echo  $current_user->user_login . "";
          
    ?>/edit/">
    

    Where mysite.com is your site name

    If using custom menus, add the page to the menu.

    And it works !


    aravindbachu
    Participant

    @aravindbachu

    @robin-w , I am sorry for those remarks. I am actually more frustrated with myself for not being able to come up with a solution for that.

    I have also seen that you have tried a lot to answer this particular question plaguing this board.

    I have already tried Ronthai’s solution, but this is what pops up on my page :

    Parse error: syntax error, unexpected ‘/’ in /home/knolzgig/public_html/wp-content/plugins/wp-exec-php/wp-exec-php.php(652) : eval()’d code on line 4

    I am unable to understand this now. there were / in many places… and I didn’t understand which one was causing the trouble, which unexpectedly shouldn’t have come in the first place.


    aravindbachu
    Participant

    @aravindbachu

    @robin-w , I am sorry for those remarks. I am actually more frustrated with myself for not being able to come up with a solution for that.

    I have also seen that you have tried a lot to answer this particular question plaguing this board.

    I have already tried Ronthai’s solution, but this is what pops up on my page :

    Parse error: syntax error, unexpected ‘/’ in /home/knolzgig/public_html/wp-content/plugins/wp-exec-php/wp-exec-php.php(652) : eval()’d code on line 4

    I am unable to understand this now. there were / in many places… and I didn’t understand which one was causing the trouble, which unexpectedly shouldn’t have come in the first place.


    Robin W
    Moderator

    @robin-w

    Ok, thanks for clarifying.

    Suspect this could be because your path is slightly different.

    Can you go into a profile edit for me , that is into bbpress and then go into edit for a real username

    The in the url you should be something like

    http://mysite.com/forums/users/admin/edit

    Post on here what that path looks like. You can substitute mysite.com for your site, and admin for whatever username you are using, it is the stuff around that I am after.


    aravindbachu
    Participant

    @aravindbachu


    Robin W
    Moderator

    @robin-w

    ok, that all looks fine.

    The error as far as I can work out says that it has an unexpected ‘/ ‘ on the evaluated code on line 4 – so for the code in the profile page line 4 is

    ?>/edit/">
    

    However this may not be a line 4 error, but something that is missing or not evaluating correctly on an earlier line.

    I’d try the following

    Recheck that the code is pasted exactly as it should be, with no missing characters eg ‘;’s from ends of lines etc. The lines posted in my previous post go passed the visible, so did you scroll to the right – just checking the obvious first !

    that your domain is spelled correctly etc.

    Then I’d try removing the / from the start of line 4 – the edit bit, and the from the end of the edit bit – I don’t think that’s the problem, but try it anyway.

    The just form my sanity copy the code from your page back into a post here, and I try it on my site to see if I get the error.

    Then we’ll see where we go from there !
    `


    aravindbachu
    Participant

    @aravindbachu

    I copied and pasted the stuff exactly as you said, and after updating the page, this piece of code :

    echo $current_user->user_login . "";

    is turning into this :

    echo $current_user-/>user_login . "";

    Its happening whenever i am updating the page by saving it.


    Robin W
    Moderator

    @robin-w

    ahh..if you are saving in ‘text’ view, try changing to ‘visual’ or if you are in visual view try going to text. Sometimes the editor does funny things to stuff it sees as code. Once you have fixed it, try and not edit anything on the page, or if you do check whether it has changed the code, and change the code back as last thing.

    It’s an annoying bug in the wordpress editor where it get’s over-keen to ensure that code doesn’t screw up how it stores, but I’d prefer it to do that than muck up the database !


    vegas778
    Participant

    @vegas778

    Hi guys.

    Do you know where I can find the file to edit the bbpress profile page for members ?

    And how do I get those links (last topics, last replied, subscriptions, favorites, edit) on the profile page ? I only see the text of the number of replies, answers and if it is a administrator or user…

    thanks


    Robin W
    Moderator

    @robin-w

    To edit what details the user can see/edit within the profile page then the template is

    wp-content/plugins/bbpress/templates/default/bbpress/form-user-edit.php
    and
    wp-content/plugins/bbpress/templates/default/bbpress/user-profile.php

    EDIT

    found the subscription/edit bit

    wp-content/plugins/bbpress/templates/default/bbpress/user-details.php


    aravindbachu
    Participant

    @aravindbachu

    hi Robin,

    I tried both ways already. It mashes up in both the ways.

    Can you suggest me how to get the black admin bar for the users above my site, just like bbpress has it now for its user at the top of the page?

    Is it possible that I make it visible and available only to logged in forums – users??


    Robin W
    Moderator

    @robin-w

    OK, so if we move outside the menu bar, you could have it after the breadcrumbs on the forum page

    Add this to your functions file

    //action to add "amend profile" to top of forums pages
    function rw_edit_profile () {
    	if (is_user_logged_in()) {
    		$user      = get_userdata( $user_id );
    		$name      = esc_attr( $user_name );
    		$user_link = '<br><a href="http://gos.rewweb.co.uk/forums/users/' . $user . '/edit">My Profile/Edit Profile</a>';
    		echo $user_link ; }
    }
    add_action('bbp_template_before_forums_loop','rw_edit_profile') ;

    But if you want to go the admin bar route, then the admin bar doesn’t show to not logged in users,
    just change each of your users to “show toolbar” in dashboard>user>edit


    Robin W
    Moderator

    @robin-w

    OK FINAL ANSWER

    Have finally got it working in the menu (and corrected the error in the post above!) !

    so for menu have

    // 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;
    }
    
    

    For on the forum page have

    //action to add "amend profile" to top of forums pages
    function rw_edit_profile () {
    	if (is_user_logged_in()) {
    	$current_user = wp_get_current_user();
    	$user=$current_user->user_login ;
    	$user_link = '<br><a href="http://www.mysite.com/forums/users/' . $user . '/edit">My Profile/Edit Profile</a>';
    	echo $user_link ; }
    }
    
    add_action('bbp_template_before_forums_loop','rw_edit_profile') ;
    
    

    aravindbachu
    Participant

    @aravindbachu

    Hi Robin.

    Thanks a zillion for the tweak. It does work wonderful enough!!.

    I have a little doubt : I have three menus in my theme, but I want to make it appear in only one menu. can you untie that knot for me?


    aravindbachu
    Participant

    @aravindbachu

    and robin, it is taking rather long time to open the edit page after clicking the edit button. Is that a problem from my webhost or the code?


    Robin W
    Moderator

    @robin-w

    speed wise – this executes as fast as any other menu command on my websites

    which menu do you want it to appear on, and is it a custom menu?


    ebarcena
    Participant

    @ebarcena

    Hi Robin,

    Your solution the menu worked for but it displays in all my menus. How can I make it display in a custom menu?

    Thanks!


    ebarcena
    Participant

    @ebarcena

    A temporary fix:

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

    and then add this in your CSS file:

    .edit-my-profile {display: none;}

    I’m still interested in getting Robin’s function to work without the CSS fix.


    ebarcena
    Participant

    @ebarcena

    sorry I forgot to mention that you should include the nav parent id for all the menus where you don’t want the link do be displayed:

    #main-nav .edit-my-profile, #footer-nav .edit-my-profile, #any-nav .edit-my-profile {
    display: none;
    }

    Robin W
    Moderator

    @robin-w

    great, looks like a solution !

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