Navigation API

BuddyPress’s Navigation API (BP 2.6+) provides an interface for developers to modify BP’s nav menus in group and user contexts.

Examples Examples

Changing the position of the user’s Notifications nav item Changing the position of the user’s Notifications nav item

[code language=”php”]
function bpcodex_change_notifications_nav_position() {
buddypress()->members->nav->edit_nav( array(
‘position’ => 999,
), ‘notifications’ );
}
add_action( ‘bp_setup_nav’, ‘bpcodex_change_notifications_nav_position’, 100 );
[/code]

Top ↑

Changing the name of the Unread subnav item of the user’s Notifications nav menu Changing the name of the Unread subnav item of the user’s Notifications nav menu

[code language=”php”]
function bpcodex_change_unread_nav_name() {
buddypress()->members->nav->edit_nav( array(
‘name’ => ‘My Unread Notifications’,
), ‘unread’, ‘notifications’ );
}
add_action( ‘bp_setup_nav’, ‘bpcodex_change_unread_nav_name’, 100 );
[/code]

Top ↑

Listing all navigation items belonging to the current group Listing all navigation items belonging to the current group

[code language=”php”]
function bpcodex_get_current_group_nav_items() {
// Group nav items are technically subnavs of the top-level item with the current group’s slug.
return buddypress()->groups->nav->get_secondary( array(
‘parent_slug’ => bp_get_current_group_slug(),
) );
}
[/code]

Top ↑

Change item names of user’s and group’s nav menus Change item names of user’s and group’s nav menus

Profile menu
[code language=”php”]
function bpcodex_rename_profile_tabs() {

buddypress()->members->nav->edit_nav( array( ‘name’ => __( ‘My Buddy Forums’, ‘textdomain’ ) ), ‘forums’ );
buddypress()->members->nav->edit_nav( array( ‘name’ => __( ‘My Buddy Groups’, ‘textdomain’ ) ), ‘groups’ );

}
add_action( ‘bp_actions’, ‘bpcodex_rename_profile_tabs’ );
[/code]

Group menu
[code language=”php”]
function bpcodex_rename_group_tabs() {

if ( ! bp_is_group() ) {
return;
}

buddypress()->groups->nav->edit_nav( array( ‘name’ => __( ‘Group Discussion’, ‘buddypress’ ) ), ‘forum’, bp_current_item() );
}
add_action( ‘bp_actions’, ‘bpcodex_rename_group_tabs’ );
[/code]

Top ↑

Changing the position of group’s nav items Changing the position of group’s nav items

[code language=”php”]
function bpcodex_group_tab_reorder() {

if( bp_is_group() ) {
buddypress()->groups->nav->edit_nav( array( ‘position’ => 1 ), ‘forum’, bp_current_item() );
buddypress()->groups->nav->edit_nav( array( ‘position’ => 2 ), ‘send-invites’, bp_current_item() );
buddypress()->groups->nav->edit_nav( array( ‘position’ => 4 ), ‘home’, bp_current_item() );
}
}
add_action( ‘bp_actions’, ‘bpcodex_group_tab_reorder’ );
[/code]

Top ↑

Remove subnav tabs from Group Settings Remove subnav tabs from Group Settings

[code language=”php”]
function bpcodex_remove_group_manager_subnav_tabs() {
// site admin will see all tabs
if ( ! bp_is_group() || ! ( bp_is_current_action( ‘admin’ ) && bp_action_variable( 0 ) ) || is_super_admin() ) {
return;
}
// all subnav items are listed here.
// comment those you want to show
$hide_tabs = array(
// ‘group-settings’ => 1,
‘delete-group’ => 1,
‘group-avatar’ => 1,
// ‘group-invites’ => 1,
‘manage-members’ => 1,
// ‘forum’ => 1,
// ‘group-cover-image’ => 1
);

$parent_nav_slug = bp_get_current_group_slug() . ‘_manage’;

//Remove the nav items
foreach ( array_keys( $hide_tabs ) as $tab ) {
bp_core_remove_subnav_item( $parent_nav_slug, $tab, ‘groups’ );
}
}
add_action( ‘bp_actions’, ‘bpcodex_remove_group_manager_subnav_tabs’ );
[/code]