Andy asks
Hey @UKGenesis @GenesisWPguide #genesiswp: how do I change layout based on if page is a parent or has children? Any ideas??
— Andy Moore (@that_web_guy) May 27, 2016
Adding the following in child theme’s functions.phps will apply content-sidebar
layout to all static Pages that have children and overrides the default layout set in Genesis theme settings (but not the one applied at Page level):
// Apply layout to static Pages that have children (subpages) | |
add_action( 'get_header', 'sk_force_layout' ); | |
function sk_force_layout() { | |
global $post; | |
// if we are on a static Page and if it does not have a parent | |
if ( is_singular( 'page' ) && !$post->post_parent ) { | |
add_filter( 'genesis_pre_get_option_site_layout', '__genesis_return_content_sidebar' ); | |
} | |
} |
References:
https://sridharkatakam.com/apply-layout-genesis-conditionally/
https://sridharkatakam.com/useful-functions-checking-pages-sub-pages-wordpress/