Skip to content

Instantly share code, notes, and snippets.

@craigsimps
Created June 21, 2018 17:56
Show Gist options
  • Save craigsimps/71dfad66ee093c67bbde1d4b254ee665 to your computer and use it in GitHub Desktop.
Save craigsimps/71dfad66ee093c67bbde1d4b254ee665 to your computer and use it in GitHub Desktop.
<?php
add_action( 'genesis_before_sidebar_widget_area', __NAMESPACE__ . '\\sidebar_switcher' );
/**
* Conditionally replace the sidebar.
*
* @since 1.0.0
*/
function sidebar_switcher() {
// Switch to a different sidebar for 'project_post_type' CPT.
if ( 'project_post_type' === get_post_type() && is_active_sidebar( 'project-post-type-sidebar' ) ) {
remove_action( 'genesis_sidebar', 'genesis_do_sidebar' );
add_action( 'genesis_sidebar', function(){
dynamic_sidebar( 'project-post-type-sidebar' );
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment