Site icon WP Smith

How to Switch Primary Sidebar to Secondary Sidebar for a Specific Page in Genesis

For one of my sites, the person wanted to use two different sidebars: one for his store and another for his blog. The rest of the site was full-width layout. So we used the two sidebars: Primary (sidebar) and Secondary (sidebar-alt). So here's how to switch sidebars (without using Nathan's phenomenal plugin Simple Sidebars) using functions.php.

[php]//switch sidebars
add_action('get_header','change_genesis_sidebar');
function change_genesis_sidebar() {
$pages = array(181);

if ( is_page($pages)) {
remove_action( 'genesis_sidebar', 'genesis_do_sidebar' );
add_action( 'genesis_sidebar', 'genesis_do_sidebar_alt' );
}
} [/php]

This code can be easily adapted to be done based on category, archives, author, etc. See the conditional tags for more details.