Skip to content

Instantly share code, notes, and snippets.

@jonschr
Created November 3, 2015 05:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonschr/3cd8ed9d6d4d83b182ec to your computer and use it in GitHub Desktop.
Save jonschr/3cd8ed9d6d4d83b182ec to your computer and use it in GitHub Desktop.
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