How to make BuddyPress Members and Groups pages obey their Page layout setting in Genesis

Posted on

Over in Genesis Slack chat a user asked,

Has anyone got some code lying around that makes BuddyPress pages actually respect the genesis layout selection?

We can use the code from How to make Posts page obey its Page layout setting in Genesis article and tweak it so that layout selected for the Members page (auto generated when BuddyPress is activated) in the back end gets applied to it in the front end.

Add the following in child theme’s functions.php:

/**
 * Make BuddyPress Members page obey its Page layout setting
 */
add_filter( 'genesis_pre_get_option_site_layout', 'sk_do_members_page_layout' );
function sk_do_members_page_layout( $opt ) {

	// if the current page is not the members directory, abort.
	if ( ! bp_is_members_directory() ) {
		return;
	}

	// get the list of BuddyPress pages from wp_options table
	$page_array = get_option( 'bp-pages' );

	$opt = get_post_meta( $page_array['members'], '_genesis_layout', true ); // where $page_array['members'] is the ID of BuddyPress Members page

	return $opt;

}