neilgee
5/1/2014 - 9:57 AM

Set sidebar conditionally to target tags, categories and posts in Genesis.php

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
}