How to Add Multiple Sidebars to WordPress

First thing, open your theme’s functions.php (or create the file if it is not already there), then insert the following code:

<?php
if ( function_exists('register_sidebar') )  /* for compatibility with old WordPress versions */
 register_sidebar('name=Left Side Bar');
 register_sidebar('name=Right Side Bar');
?>

That creates two sidebars for us, one named ‘Left Side Bar’and the other named ‘Right Side Bar’.

Then create two other files:

  • sidebar-left.php
  • sidebar-right.php

In sidebar-left.php insert the following code:

<?php if ( function_exists('dynamic_sidebar') && dynamic_sidebar(1) ) : ?>

<!-- Your sidebar contents here -->
<?php endif; ?>

In sidebar-right.php insert the following code:

<?php if ( function_exists('dynamic_sidebar') && dynamic_sidebar(2) ) : ?>

<!-- Your sidebar contents here -->
<?php endif; ?>

Final step is to include the sidebars in your template, so locate your main template file and insert the following lines where you want the sidebars to appear

<?php include (TEMPLATEPATH . '/sidebar-left.php'); ?>
<?php include (TEMPLATEPATH . '/sidebar-right.php'); ?>

NOTES

Instead of using ids you could also use text strings when calling the dynamic sidebars. So for example in sidebar-left.php we could have used the code:

<?php if ( function_exists('dynamic_sidebar') && dynamic_sidebar('Left Side Bar') ) : ?>
<?php endif; ?>

This is mostly convenient when you have many sidebars and thus it would not be very intuitive to use their ids.

Also if you just wanted to have static sidebars with predefined content which cannot be changed, all you need to do is create the two sidebar files, then include them in the template as shown above. In this case there is no need to edit the functions.php file and to include the dynamic_sidebar code in the sidebar files.

For further reading about this topic check out the following links:

http://www.blogohblog.com/adding-extra-sidebar-to-your-wordpress-theme/

http://bloggingexperiment.com/archives/adding-sidebars-to-wordpress-themes.php

http://bloggingexperiment.com/archives/add-widgets-wordpress-themes.php

http://www.quickonlinetips.com/archives/2007/11/how-to-create-multiple-dynamic-sidebars-for-wordpress-widgets/

<?php include (TEMPLATEPATH . ‘/sidebar-left.php’); ?>

Related posts:

  1. WordPress Settings API Multiple Select Box (Combo Box)
  2. WordPress: Include a Different Sidebar for Certain Pages
  3. Best WordPress Calendar Plugin
  4. Coding Standards – Spacing Between Tokens
  5. Plugins to Add Multiple Columns on Your WordPress Page

2 Comments

Got something to say? Feel free, I want to hear from you! Leave a Comment

  1. Hi,in my first visit here i got this worthy tutorial. I will use it for my wordpress blog. Thanks buddy.

  2. Jean Galea says:

    Glad you found it useful :)

Leave a Comment

Let us know your thoughts on this post but remember to place nicely folks!