Looking to display
- a specific custom sidebar (widget area container) for archives (Posts page, category/tag/author/search results etc. archives) and single blog post pages
- widgets of custom another sidebar on static Pages
in the Primary Sidebar location of your Genesis site?
Just add the following in your child theme’s functions.php
// Register Blog Sidebar widget area
genesis_register_widget_area(
array(
'id' => 'blog-sidebar',
'name' => __( 'Blog Sidebar', 'my-theme-text-domain' ),
'description' => __( 'Primary sidebar for blog pages', 'my-theme-text-domain' ),
)
);
// Register Page Sidebar widget area
genesis_register_widget_area(
array(
'id' => 'page-sidebar',
'name' => __( 'Page Sidebar', 'my-theme-text-domain' ),
'description' => __( 'Primary sidebar for static pages', 'my-theme-text-domain' ),
)
);
add_action( 'genesis_after_header', 'sk_change_genesis_primary_sidebar' );
/**
* Show custom sidebars in Primary Sidebar location for blog pages and static Pages
*/
function sk_change_genesis_primary_sidebar() {
if ( ! is_singular() || is_single() ) { // for archives and single post pages
// remove Primary Sidebar from the Primary Sidebar area
remove_action( 'genesis_sidebar', 'genesis_do_sidebar' );
// show Blog Sidebar in Primary Sidebar area
add_action( 'genesis_sidebar', function() {
dynamic_sidebar( 'blog-sidebar' );
} );
}
if ( is_page() ) { // for static Pages
// remove Primary Sidebar from the Primary Sidebar area
remove_action( 'genesis_sidebar', 'genesis_do_sidebar' );
// show Page Sidebar in Primary Sidebar area
add_action( 'genesis_sidebar', function() {
dynamic_sidebar( 'page-sidebar' );
} );
}
}
Now you will find two additional sidebars at Appearance > Widgets, “Blog Sidebar” and “Page Sidebar”. Drag your desired widgets into these to have them appear conditionally as defined in the code above.
Reference: https://sridharkatakam.com/conditional-display-primary-secondary-navigation-menus-sidebars-genesis/
How about activating the sidebar for a particular page based upon a template? Is it too late in the build to activate the sidebar in the template itself?
https://sridharkatakam.com/set-custom-primary-sidebar-pages-using-page-template/
[…] the comments section of How to set up different sidebars for archives and Pages in Genesis a user […]