Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Assigning sidebars programatically
<?php
// Don't include the opening php tag
/**
* Assign the sidebars
*/
add_action( 'genesis_header','prefix_change_genesis_sidebar' );
function prefix_change_genesis_sidebar() {
global $post;
if ( get_post_type() == 'post' ) { // Check if we're on a single post for the 'post' post type
remove_action( 'genesis_sidebar', 'genesis_do_sidebar'); // remove the default genesis sidebar
remove_action( 'genesis_sidebar', 'gencwooc_ss_do_sidebar' ); // remove the woocommerce sidebar
remove_action( 'genesis_sidebar', 'ss_do_sidebar' ); // remove the default sidebar added by genesis simple sidebars
add_action( 'genesis_sidebar', 'prefix_do_blog_sidebar' ); // call the function for my custom sidebar
}
if ( get_post_type() == 'product' ) { // Check if we're on a single post for the 'product' post type
remove_action( 'genesis_sidebar', 'genesis_do_sidebar'); // remove the default genesis sidebar
remove_action( 'genesis_sidebar', 'gencwooc_ss_do_sidebar' ); // remove the woocommerce sidebar
remove_action( 'genesis_sidebar', 'ss_do_sidebar' ); // remove the default sidebar added by genesis simple sidebars
add_action( 'genesis_sidebar', 'prefix_do_products_sidebar' ); // call the function for my custom sidebar
}
}
//* Output the products sidebar
function prefix_do_products_sidebar() {
dynamic_sidebar( 'products' );
}
//* Output the blog sidebar
function prefix_do_blog_sidebar() {
dynamic_sidebar( 'blog' );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment