GeneratePress: No Sidebar on Selected Post Types
Removes the sidebar in GeneratePress for the post types and archives you list, for full-width shop, course or portfolio pages.
Opens WPIDE on
Code
// Post types that should be full width.
$wpide_gp_full_types = array( 'product', 'page' );
add_filter( 'generate_sidebar_layout', function ( $layout ) use ( $wpide_gp_full_types ) {
if ( is_singular( $wpide_gp_full_types ) || is_post_type_archive( $wpide_gp_full_types ) ) {
return 'no-sidebar';
}
return $layout;
} );
Notes
Layout values GeneratePress accepts: no-sidebar, right-sidebar, left-sidebar, both-sidebars.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.