WordPress Multiple Sidebars

October 13th, 2011

Seems there are a lot of complicated ways to add multiple sidebars to a wordpress theme, so here is a simpler one. Add this to your functions.php file for the theme.

add_action( 'widgets_init', 'add_sidebars' );
function add_sidebars() {
  register_sidebar(
    array(
      'id' => 'right',
      'name' => __( 'right' ),
      'description' => __( 'Right Sidebar' ),
      'before_widget' => '<div id="%1$s" class="widget %2$s">',
      'after_widget' => '</div>',
      'before_title' => '<h3>',
      'after_title' => '</h3>'
    )
  );
  register_sidebar(
    array(
      'id' => 'left',
      'name' => __( 'left' ),
      'description' => __( 'Left Sidebar' ),
      'before_widget' => '<div id="%1$s" class="widget %2$s">',
      'after_widget' => '</div>',
      'before_title' => '<h3>',
      'after_title' => '</h3>'
    )
  );
  // add however many more are needed..
}

Then to place the sidebars in your theme just use:

<?php
  dynamic_sidebar( 'right' );
  dynamic_sidebar( 'left' );
?>

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>