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

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

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

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

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

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

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

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