Search
Close this search box.

How to modify profile tab order in BuddyPress

To modify the order of the profile tabs in BuddyPress with functions.php, you can use the bp_nav function and the bp_core_new_nav_item function in your theme’s functions.php file.

Here’s an example of how you can use these functions to modify the order of the profile tabs:

// Modify profile tab order in BuddyPress
// More snippets at wpunplugged.com 

function my_custom_nav_setup() {
	// Get the default profile navigation
	$nav = bp_get_nav( 'profile' );

	// Remove the default profile navigation
	bp_core_remove_nav_item( 'profile' );

	// Add the profile navigation in the new order
	bp_nav( array(
		'name'                    => $nav[ 'name' ],
		'slug'                    => $nav[ 'slug' ],
		'position'                => 10,
		'show_for_displayed_user' => $nav[ 'show_for_displayed_user' ],
		'screen_function'         => $nav[ 'screen_function' ],
		'default_subnav_slug'     => $nav[ 'default_subnav_slug' ],
		'item_css_id'             => $nav[ 'css_id' ],
		'user_has_access'         => $nav[ 'user_has_access' ],
		'subnav_items'            => $nav[ 'sub_nav' ]
	) );
}
add_action( 'bp_setup_nav', 'my_custom_nav_setup', 100 );

This code will remove the default profile navigation and add it back in a new order, with a position of 10. You can change the position value to specify the order in which the profile tabs should appear.

You can also modify the order of the subnav items within a profile tab using the bp_core_new_subnav_item function. Here’s an example of how you can use this function:

// Modify profile tab order in BuddyPress
// More snippets at wpunplugged.com 

function my_custom_subnav_setup() {
	// Get the default "Activity" subnav
	$nav = bp_get_nav( 'activity' );

	// Remove the default "Activity" subnav
	bp_core_remove_subnav_item( 'activity' );

	// Add the "Activity" subnav in the new order
	bp_core_new_subnav_item( array(
		'name'            => $nav[ 'name' ],
		'slug'            => $nav[ 'slug' ],
		'parent_slug'     => $nav[ 'parent_slug' ],
		'parent_url'      => $nav[ 'parent_url' ],
		'screen_function' => $nav[ 'screen_function' ],
		'position'        => 10,
		'item_css_id'     => $nav[ 'css_id' ]
	) );
}
add_action( 'bp_setup_nav', 'my_custom_subnav_setup', 100 );

This code will remove the default “Activity” subnav and add it back in a new order, with a position of 10. You can change the position value to specify the order in which the subnav items should appear. You can repeat this process for any other profile tabs or subnav items that you want to modify the order of. Just be sure to use the correct slug for the navigation item or subnav item that you want to modify.

Share this post

You might also like...

Comment

Your email address will not be published. Required fields are marked *