Switch Genesis Sidebars

sidebar-sidebar-content1

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' );
    }
 
}
view raw gistfile1.aw This Gist brought to you by GitHub.

Bill Erickson is a WordPress Consultant who builds custom websites using WordPress as a CMS and the Genesis framework. He contributes to the WordPress community through free themes, plugins, tutorials, and core patches. He's also a cofounder of the BIL Conference (the open analog to the TED Conference).

Looking for more great tutorials? See them all!

Speak Your Mind

*

If you'd like to include code in your post, please post it to http://gist.github.com and include a link.