Skip to:
Content
Pages
Categories
Search
Top
Bottom
Codex HomeDeveloper Resources → Navigation API

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

Changing the position of the user’s Notifications nav item

1
2
3
4
5
6
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 );

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

1
2
3
4
5
6
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 );

Listing all navigation items belonging to the current group

1
2
3
4
5
6
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(),
    ) );
}

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

Profile menu

1
2
3
4
5
6
7
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' );

Group menu

1
2
3
4
5
6
7
8
9
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' );

Changing the position of group’s nav items

1
2
3
4
5
6
7
8
9
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' );

Remove subnav tabs from Group Settings

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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' );
Skip to toolbar