Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save neilgee/e186ae9de24b3f39ce16 to your computer and use it in GitHub Desktop.
Save neilgee/e186ae9de24b3f39ce16 to your computer and use it in GitHub Desktop.
Set sidebar conditionally to target tags, categories and posts in Genesis.php
<?php
//do not copy the above opening php tag
add_action( 'genesis_before_sidebar_widget_area', 'themeprefix_remove_sidebar' ); // starts the ball rolling
/**
* Conditionally Change Sidebar in Genesis whilst using Simple Sidebars
*
* @package Genesis Sidebar with Simple Sidebar Switcheroo
* @author Neil Gee
* @link https://wpbeaches.com/bulk-set-sidebar-categories-tags-simple-sidebars-installed-genesis/
* @copyright (c) 2014, Neil Gee
*/
function themeprefix_remove_sidebar() {
if ( is_single() || is_category() || is_tag() ) { // set your connditionals here
remove_action( 'genesis_sidebar', 'ss_do_sidebar' ); // removes Simple Sidebar
remove_action( 'genesis_sidebar', 'genesis_do_sidebar' ); // removes Genesis Default sidebar
add_action( 'genesis_sidebar', 'themeprefix_add_sidebar' ); // adds alternative sidebar in function below
}
}
// Alternative Sidebar
function themeprefix_add_sidebar() {
dynamic_sidebar( 'category-sidebar' ); // add in the ID of the sidebar you want to replace it with
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment