Skip to content

Instantly share code, notes, and snippets.

@stephanieleary
Created October 16, 2016 19:34
Show Gist options
  • Save stephanieleary/132adc4a628327e2f487804ed25b6b1c to your computer and use it in GitHub Desktop.
Save stephanieleary/132adc4a628327e2f487804ed25b6b1c to your computer and use it in GitHub Desktop.
CPT-specific sidebars
<?php
add_action( 'get_header', 'scl_cpt_switch_sidebar' );
function scl_cpt_switch_sidebar() {
remove_action( 'genesis_sidebar', 'genesis_do_sidebar' );
add_action( 'genesis_sidebar', 'scl_do_sidebar' );
}
function scl_do_sidebar() {
if ( is_page_template( 'page_whitepaper.php' ) ) {
dynamic_sidebar( 'whitepaper' );
return;
}
if ( function_exists( 'scl_find_post_type' ) )
$type = tees_find_post_type();
else
$type = get_query_var( 'post_type' );
if ( is_home() && !is_front_page() )
$type = 'post';
if ( isset( $type ) && !empty( $type ) && is_active_sidebar( $type ) && !in_array( $type, array( 'any', 'page', 'attachment' ) ) )
dynamic_sidebar( $type );
else
genesis_do_sidebar();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment