Reordering BuddyPress User Profile tabs
BuddyPress 2.6.0 introduced simpler ways to organize nav items. If you are looking for ways to reorder, It is very simple.
Before we dive into code, some basics first.
BuddyPress uses numeric position as a way to sort the nav items. The nav items are ordered in ascending order(lower values come first). We can use the edit_nav() method of the BP_Core_Nav class to update the position.
To update the position of a user profile nav item, you can use the following code
1 | buddypress()->members->nav->edit_nav( array( 'position' => $new_position ), $nav_slug ); |
Please make sure to change the $nav_slug with the actual nav item slug and the $new_position with a number.
In the function, the first argument is the details we want to update and the second argument is the slug of the nav item.
Example:-
Here is a complete example of reorganizing multiple profile tabs. It is not necessary to reorder all tabs, you may only order the relevant tabs for you.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | /** * Reorder BuddyPress profile tabs/navigation. */ function buddydev_reorder_buddypress_profile_tabs() { $nav = buddypress()->members->nav; // it's a map of nav items for user profile. // mapping component slug to their position. $nav_items = array( 'settings' => 10, // first. 'activity' => 20, 'friends' => 30, 'groups' => 40, 'blogs' => 50, 'messages' => 60, 'profile' => 70, ); foreach ( $nav_items as $nav_item => $position ) { $nav->edit_nav( array( 'position' => $position ), $nav_item ); } } add_action( 'bp_setup_nav', 'buddydev_reorder_buddypress_profile_tabs', 999 ); |
And the result:-
Please update the position as you wish. You should put the in your bp-custom.php.
Have fun!
People could also use the free BuddyPress Reorder Tabs plugin from BuddyBoss. Works just fine, and can also reorder tabs for groups.
Hi Nathan,
Thank you for the comment.
The BuddyBoss Reorder Tabs plugin is buggy. It overwrites all tabs. I am not sure if it works properly now. But I remember it causing me a headache as it almost overtook the tabs and some new custom tabs disappeared because of it.
Also, the plugin is bulky and I don't see any point in using the plugin if you are a developer. The code is aimed at developer.
As for groups, you can adapt the same code for groups, all you need to change is buddypress()->members->nav to buddypress()->groups->nav;
Can you also do this to completely delete some of these tabs? Rather than hiding it via CSS?
Hi Graham,
My apologies for the delayed reply.
You can use the same action to delete a link. All you need to do is use this function
and for sub navs
Please make sure you don't delete the default sub nav. It is problematic.
Regards
Brajesh
Is there a way to move the items underneath another tab. For example i want to move settings and notifications under profile.
Hi Aly,
You can do that by using css to hide the notification tab and adding the link to current user's notification as child of the profile.
Please do not remove the notification link using the code for nav removal or the screens will break.