How to Add a Second Sidebar to Your WordPress Theme

This tutorial will cover how to add a second sidebar to your WordPress theme. This is very useful when you have a 3 column layout.

WordPress 2.5 introduced the name parameter to the include tag get_sidebar().

We are going to add a widgetized left sidebar and a widgetized right sidebar to a 3 column layout.

Step 1: Create 2 files, named sidebar.php and sidebar-right.php.

Code for sidebar.php

<?php
/**
Template Name: Sidebar
 */
?>
<div id="sidebar">
<ul>
<?php 	/* Widgetized sidebar, if you have the plugin installed. */
if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar() ) : ?>
<?php endif; ?>
</ul>
</div>

The id of the sidebar can be anything you would like. The code between the php tags should not be changed.

Code for sidebar-right.php

<?php
/**
Template Name: Sidebar Right
 */
?>
<div id="sidebar-right">
<ul>
<?php 	/* Widgetized sidebar, if you have the plugin installed. */
if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Sidebar Right') ) : ?>
<?php endif; ?>
</ul>
</div>

The id of the sidebar can be anything you would like. The code between the php tags should not be changed.

Step 2: Add the following to your template files where you would like your sidebars to display in your layout. The most template files are archive.php, category.php, index.php, page.php and single.php. The WordPress Codex has a tutorial on template pages and template hierarchy.

<?php get_sidebar(); ?>
<?php get_sidebar('right'); ?>

Step 3: Add this to your functions.php page.

<?php
if ( function_exists('register_sidebar') )
    register_sidebar(array(
        'before_widget' => '<li id="%1$s" class="widget %2$s">',
        'after_widget' => '</li>',
'before_title' => '<h2 class="widgettitle">',
        'after_title' => '</h2>',
    ));

    register_sidebar(array('name'=>'sidebar-right'
    ));

Below is what it should look like in your WordPress admin panel.
Widget Admin

Share and Enjoy:
  • Print
  • Digg
  • StumbleUpon
  • del.icio.us
  • Facebook
  • Yahoo! Buzz
  • Twitter
  • Google Bookmarks
  • Add to favorites
About Jeffrey Horen

I am the owner of Excelnet Media. We are a full service, one stop interactive web agency building extraordinary websites with extraordinary customer service for extraordinary clients.

Comments

  1. Hey Jeff,

    I’m about to give your guide shot, I’m really in need of a second sidebar and am about to cry if it doesn’t work.

    Thanks in advance though its one of few tutorials with code examples that aren’t poo.

Speak Your Mind

*