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' );
    }
 
}

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!

Comments

  1. Julie says:

    Hi Bill

    Thanks very much for this… is there a way to specifically apply this just to a category or page rather than the whole site – ie I want a three column layout for my blog where the rest of the site is two column. At the moment the secondary sidebar is moving to the place where the primary sidebar is located on the rest of the site. I am using layout extras for the blog to default to 3 columns (sidebar-content-sidebar).

    thanks

    • Bill Erickson says:

      Yes, just change the if statement to include your conditional. Ex:

      if( 'sidebar-sidebar-content' == $site_layout && is_category() )

  2. Shelley says:

    Is it possible to do this in Simple Hooks so that it can be applied to one site in a network instead of to all of them?

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.