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; | |
} |
References:
https://buddypress.org/support/topic/how-to-find-page-id-for-default-buddypress-pages/#post-177781
http://buddypress.wp-a2z.org/oik_api/bp_is_members_directory/
https://wordpress.org/plugins/query-monitor-bbpress-buddypress-conditionals/
Sample screenshots:
Back end:
Front end:
Update on February 15, 2017:
If you’d like this to work on BuddyPress Groups page in addition to the Members page, use this code instead:
add_filter( 'genesis_pre_get_option_site_layout', 'sk_do_buddypress_page_layout' ); | |
/** | |
* Make BuddyPress Members and Groups pages obey their Page layout setting | |
*/ | |
function sk_do_buddypress_page_layout( $opt ) { | |
// if the current page is not the members directory or groups page, abort. | |
if ( ! ( bp_is_members_directory() || bp_is_groups_component() ) ) { | |
return; | |
} | |
// get the list of BuddyPress pages from wp_options table | |
$page_array = get_option( 'bp-pages' ); | |
if ( bp_is_members_directory() ) { | |
$opt = get_post_meta( $page_array['members'], '_genesis_layout', true ); | |
// where $page_array['members'] is the ID of BuddyPress Members page | |
} | |
if ( bp_is_groups_component() ) { | |
$opt = get_post_meta( $page_array['groups'], '_genesis_layout', true ); | |
// where $page_array['groups'] is the ID of BuddyPress Groups page | |
} | |
return $opt; | |
} |
Is this code still working for anyone? I just tried it, with no success.
Thank you!
I’ve just tested this in Genesis Sample and it is working fine.
What is the URL of your BuddyPress Members page?
Thank you, Sridhar. I think I have discovered the problem. My client wanted this to work on the Groups page but it doesn’t appear to be respecting those settings at all. This code does work on the Members page–my apologies.
Is the best solution just to force the Groups page to full width with CSS?
Thank you!
Nope.
I’ve updated the tutorial and provided alternate code that takes care of Groups page as well.
Thank you so much! That worked beautifully. So appreciate it.