Adding Dynamic Profile Link to Main Menu Item
-
Buddypress = 1.5
Theme = Custom CommunityIn the wordpress menu I would like to add a link to the buddypress user profile. I would like to create a new tab on my main menu called “My Profile” that redirects to the unique buddypress user profile page. My problem is that these links are dynamic based on the username.
What I would like to achieve:
–>User1 logs in and clicks on http://website.com/my-profile and is redirected to http://website.com/members/user1/profile/–>User2 logs in and clicks on http://website.com/my-profile and is redirected to http://website.com/members/user2/profile/
I’ve searched everywhere and can’t find a solution to this vexing problem. Your help is greatly appreciated.
Thanks,
-John
-
Ciao guys, my theme does not work with menus, so do you know how to get a link to the logged in user profile to be used wherever?
add_filter( 'wp_nav_menu_items', 'my_nav_menu_profile_link' ); function my_nav_menu_profile_link($menu) { if (!is_user_logged_in() && $args->theme_location == 'footer-nav' ) return $menu; else $profilelink = '<li><a href="' . bp_loggedin_user_domain( '/' ) . '">' . __('My Profile', 'buddypress' ) . '</a></li>'; $menu = $profilelink . $menu; return $menu; }
Hey guys,
I’ve tried both the code and plugin and neither is working…
I am using a child them of bp default, with nothing much changed apart from some CSS etc.
Maybe one of the plugin I am using is conflicting? I have installed BudyPress Album, Couterize, Invite Anyone, Socialize, WP-FB-Autoconnect.
Any idea what’s going on??
InactiveHi @formbi as @modemlooper already addressed he is going to be updating the plugin so maybe its best to wait until its done and it will resolve your issue.
Working on this today so expect an update very soon
@mercime I just finished pluging in the code for a user profile page and I am having the same issue the link to main menu was not automatically created. I have been reading the post for the next steps and I am not sure what to do from here. Could you please explain how to get the profile page to link to main menu items. I am using bp community theme.
Im sorry using simple wp community
Thanks for response @modemlooper I just switched to the community theme I like it so far, going to play around with it a little. Does this plugin work for this theme also? or do I have to add the above mentioned code?
@mercime / @modemlooper installed plugin still no user profile page generated/ also tried the code nothing. I must be doing something wrong, can you PLEASE help
Plugin doesn’t create pages. Make sure you’ve created your component pages in wp admin. Settings > BuddyPress > Pages
I created a wp page titled “My Profile” but it is not creating buddypress component directory just a page. Which is what I thought the suggested code would do.
You do not need to create every page. Just the component directories.
Are you using a BP compatible theme?
I am very sure. I am not having a problem making the profile page a home page, My problem is making “My Profile” show up in my component directories. On my components page it says “Associate a WordPress Page with each BuddyPress component directory” I would like to add “My Profile” to this component directory.
Currently I have “Activity Stream = activity, Discussion Forum = Forums, Groups = Groups etc..
How can I do this, sorry my english not so good sometimes.
I’m a bit confused but the members directory will not show a single users profile. The members page you create in admin is the sites directory for members. The profile page is located after this directory.
/members/ = members directory
/members/[user_name]/ = user profileYou do not create this page. BP knows what page to use when you are on /members/[user_name]/
Do you not have a page when you click a username link on your site?
The BuddyPress Custom Profile Menu plugin should really help you out with this: https://wordpress.org/extend/plugins/buddypress-custom-profile-menu
(full disclosure: it’s our plugin )
Hello,
Thanks for the great work and help! I added the menu item and it works perfect, but only for the desktop version of the website. I’ve installed a responsive template, and when visiting the website on mobile, but also with making the desktop version smaller to mobile view, the menu item disappears!
I don’t know if it’s possible to fix this, but it would be very nice. It would also be good if a profile button could appear in a widget area, however, in the menu would be best.I hope someone can help me out. Thanks in advance!
Regards, Marcel
How did you manage to move the menu item to another location besides first or last? @modemlooper, that link to your plugin is not working anymore. I tried Buddypress custom profile menu but I am not using the Top Menu.
@mercime I tried the code you provided and it works good, only one tiny problem if you can provide a fix. When I am on the activity page for instance then I click the link for View Your Awesome Profile it takes me there as it should but the activity menu item still looks active by the color of the menu item. Its probably a CSS thing but when your active in your profile the navigation menu item still looks like the activity menu item is the active because its still got the color of being the active item even though its not. Hope this makes sense. Any suggestions on how to fix it? Thank you!
@mercime Any idea for a fix? Thank you!
I have followed your suggestion to add the Profile link to a second theme location menu. However, now it shows in both menus. How can I specify it just to show in one and not the other? Here is my code:
add_filter( 'wp_nav_menu_items', 'my_nav_menu_profile_link' ); function my_nav_menu_profile_link($menu) { if (!is_user_logged_in() && $args->theme_location == 'footer-nav' ) return $menu; else $profilelink = '<li><a href="' . bp_loggedin_user_domain( '/' ) . '">' . __('My Profile', 'buddypress' ) . '</a></li>'; $menu = $profilelink . $menu; return $menu; }
Thanks!
Don’t know if you came up with a fix for this but here’s what I did…
I used the code as you posted it (based on my menus…) and added a style sheet for the other menus to not display that menu item. A hack I know but I searched high and low for a proper solution and didn’t find one.
#menu-primary-menu .bpprofile, #menu-sidebar .bpprofile { display:none; }
Hi @mercime,
I hope you can help with this.
I have slightly altered code that you put up a year ago but am having a slight problem with it.
// Filter wp_nav_menu() to add profile link add_filter( 'wp_nav_menu_items', 'my_nav_menu_profile_link',10,2 ); function my_nav_menu_profile_link($menu, $args) { if( is_user_logged_in() && $args->theme_location == 'header2' ){ $profilelink = '<li>Welcome, <a href="' . bp_loggedin_user_domain( '/' ) . '">' . bp_loggedin_user_username() . '</a></li>'; $menu = $menu . $profilelink; } return $menu; }
Basically, I am hoping for the menu item to simply say Welcome, **Username**.
At the moment, it is displaying the username, but is actually removing it from the a tags and from the actual menu itself, so the code reads something like:
<nav id="other-navigation" class="top-navigation" role="navigation"> username <div class="menu-secondary-header-menu-container"> <ul id="menu-secondary-header-menu" class="header_menu_2"> <li id="menu-item-1865" class="menu-item-1865"> This is the first Link in the menu</li> <li>Welcome, <a href="http://www.mysite.com/profile/username/"></a></li> </ul> </div> </nav>
Hopefully you can shed some light onto this?
Cheers
Damien
Try using: bp_get_loggedin_user_username() instead of bp_loggedin_user_username().
bp_loggedin_user_username() will echo the name so it will be out of the sequence you expect.
- The topic ‘Adding Dynamic Profile Link to Main Menu Item’ is closed to new replies.