What’s the easiest way to change the default landing page for BuddyPress groups?

[Edit – My original answer will only work in the upcoming BP 1.6]

Versions of BuddyPress from 1.6 onwards

function bbg_change_group_default_extension( $default ) {
    return 'forum';
}
add_filter( 'bp_groups_default_extension', 'bbg_change_group_default_extension' );

Versions of BuddyPress prior to 1.6

For the moment, you’ll have to use something like the following, which is a modified version of bp_core_new_nav_default() (a function that is broken in the case of groups, because of various slug-related stuff):

function bbg_set_new_group_default_subnav() {
    global $bp;

    if ( bp_is_group() ) {
        // Set up your new default
        $new_screen_function = 'groups_screen_group_forum';
        $new_default_slug = 'forum';

        $parent_slug = bp_get_current_group_slug();

        if ( $function = $bp->bp_nav[$parent_slug]['screen_function'] ) {
            if ( !is_object( $function[0] ) )
                remove_action( 'bp_screens', $function, 3 );
                    else
                remove_action( 'bp_screens', array( &$function[0], $function[1] ), 3 );
        }

        $bp->bp_nav[$parent_slug]['screen_function'] = &$new_screen_function;

        if ( bp_is_groups_component() && !bp_current_action() ) {
            if ( !is_object( $new_screen_function[0] ) ) {
                add_action( 'bp_screens', $new_screen_function );

            } else {
                add_action( 'bp_screens', array( &$new_screen_function[0], $new_screen_function[1] ) );
            }

            $bp->current_action = $new_default_slug;
       }
    }
}
add_action( 'bp_setup_nav', 'bbg_set_new_group_default_subnav', 999 );

function bbg_set_new_group_default_action() {
    global $bp;

    if ( bp_is_group() && !bp_current_action() ) {
        $bp->current_action = 'forum';
    }
}
add_action( 'bp_setup_globals', 'bbg_set_new_group_default_action', 999 );

Leave a Comment