Sidebar Layout

There are two sidebars by default in GeneratePress that come with multiple layouts including:

  • Content / Sidebar
  • Sidebar / Content
  • Content (no sidebars)
  • Sidebar / Content / Sidebar
  • Sidebar / Sidebar / Content
  • Content / Sidebar / Sidebar

There are three different options you can find in Customize > Layout > Sidebars. These options apply to the entire site.

Sidebar Layout

This setting refers to your regular pages.

Blog Sidebar Layout

This setting is specific for your blog, archives, search results etc..

Single Post Sidebar Layout

This setting is specific to your single posts, including blog posts or any kind of custom post type post.

Different sidebar layouts for individual pages and posts

Some individual pages and posts might require a different layout than your global settings. In this case, you can use the meta box while editing that page/post.

Using a function

Sometimes, the global settings and individual meta box won’t be enough, and you’ll have tougher conditionals to meet like specific archive pages, categories or custom post types.

In these cases, you can use the filter to set your sidebar layouts.

For example, if we want to target WooCommerce:

add_filter( 'generate_sidebar_layout','tu_custom_woocommerce_sidebar_layout' );
function tu_custom_woocommerce_sidebar_layout( $layout )
{
 	// If we are on a woocommerce page, set the sidebar
 	if ( function_exists( 'is_woocommerce' ) && is_woocommerce() )
 	 	return 'both-left';

 	// Or else, set the regular layout
 	return $layout;

 }

Or we can target categories:

add_filter( 'generate_sidebar_layout','tu_custom_category_sidebar_layout' );
function tu_custom_category_sidebar_layout( $layout )
{
 	// If we are on a category, set the sidebar
 	if ( is_category() )
 	 	return 'no-sidebar';

 	// Or else, set the regular layout
 	return $layout;

 }

Another example is targeting the search results page:

add_filter( 'generate_sidebar_layout','tu_custom_search_sidebar_layout' );
function tu_custom_search_sidebar_layout( $layout )
{
 	// If we are viewing search results, set the sidebar
 	if ( is_search() )
 	 	return 'no-sidebar';

 	// Or else, set the regular layout
 	return $layout;

 }

You can use any of the available  WordPress conditionals to determine your sidebar layout.

These are the available IDs you can return:

left-sidebar
right-sidebar
no-sidebar
both-sidebars
both-left
both-right

Learn how to add PHP here.