Skip to content

Instantly share code, notes, and snippets.

@jacobwise
Last active April 2, 2018 03:35
Show Gist options
  • Save jacobwise/7785c2b1c32db1cb39af to your computer and use it in GitHub Desktop.
Save jacobwise/7785c2b1c32db1cb39af to your computer and use it in GitHub Desktop.
Switch Genesis Primary sidebar for a custom sidebar
<?php
//* Remove Primary Sidebar if blog, single, or CPT
add_action( 'get_header', 'jw_remove_primary_sidebar' );
function jw_remove_primary_sidebar() {
if ( is_singular( 'post' ) || is_home() || is_singular( 'code' ) || is_singular( 'tutorial' ) || is_archive() ) {
/** Remove default sidebar */
remove_action( 'genesis_sidebar', 'genesis_do_sidebar' );
}
}
//* Display different sidebar for blog and CPT's
add_action( 'genesis_sidebar', 'jw_sidebar_switcher' );
function jw_sidebar_switcher() {
if ( is_singular( 'code' ) || is_post_type_archive( 'code' ) || is_tax( 'code_category' ) ) {
genesis_widget_area( 'code-sidebar', array(
'before' => '<div class="code-sidebar widget-area">',
'after' => '</div>',
) );
}
elseif ( is_singular( 'tutorial' ) || is_post_type_archive( 'tutorial' ) || is_tax( 'tutorial_category' ) ) {
genesis_widget_area( 'tutorial-sidebar', array(
'before' => '<div class="tutorial-sidebar widget-area">',
'after' => '</div>',
) );
}
elseif ( is_singular( 'post' ) || is_home() || is_category() ) {
genesis_widget_area( 'blog-sidebar', array(
'before' => '<div class="blog-sidebar widget-area">',
'after' => '</div>',
) );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment