One of the great features of Genesis is the ability to change between many different page layouts on a per-page basis. You can have 1, 2, or 3 columns, and specify the order of the sidebar areas and content area.
But one issue you might have is which sidebar shows up in each of the sidebar areas. For example, if you select “Sidebar-Sidebar-Content,” it will be arranged as “Secondary Sidebar – Primary Sidebar – Content Area”. If you happened to have your site navigation in the Primary Sidebar, it’s now in the middle column of the page.
Before trying this, always check beforehand, if what you’re trying to do can be accomplished with CSS first. More often than not, you can re-order the sidebars correctly by simply shifting the way elements of the layout are floating. This should only be used if you need the Secondary Sidebar between the Primary Sidebar and the Content Area.
Here’s how to specify which sidebar shows up in which sidebar area on a specific page template.
<?php | |
add_action( 'genesis_after_header', 'be_change_sidebar_order' ); | |
/** | |
* Swap Primary and Secondary Sidebars on Sidebar-Sidebar-Content | |
* | |
* @author Bill Erickson | |
* @link http://www.billerickson.net/switch-genesis-sidebars/ | |
*/ | |
function be_change_sidebar_order() { | |
$site_layout = genesis_site_layout(); | |
if ( 'sidebar-sidebar-content' == $site_layout ) { | |
// Remove the Primary Sidebar from the Primary Sidebar area. | |
remove_action( 'genesis_sidebar', 'genesis_do_sidebar' ); | |
// Remove the Secondary Sidebar from the Secondary Sidebar area. | |
remove_action( 'genesis_sidebar_alt', 'genesis_do_sidebar_alt' ); | |
// Place the Secondary Sidebar into the Primary Sidebar area. | |
add_action( 'genesis_sidebar', 'genesis_do_sidebar_alt' ); | |
// Place the Primary Sidebar into the Secondary Sidebar area. | |
add_action( 'genesis_sidebar_alt', 'genesis_do_sidebar' ); | |
} | |
} |
Craig Grella says
Weird thing: I’m using the remove action code to remove primary sidebar in education child theme and it is not removing it from a custom post type single post.
Anything I Might be missing to remove primary sidebar just for single posts on custom post types?
Ravijit says
Recently, in latest wordpress update (4.7) sidebar is changed from right to left automatically. It should be fixed soon. However, this article helped alot.
Thanks