Created
November 3, 2015 05:02
-
-
Save jonschr/3cd8ed9d6d4d83b182ec to your computer and use it in GitHub Desktop.
Assigning sidebars programatically
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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