create multiple sidebars in wordpress

Author: admin
Publication date: November 23rd, 2009
Category: How to

When you develop a wordpress theme maybe you have to use two sidebars which to use them both at once or on different pages. I recently encountered with this problem and i thought that maybe there is someone else in the same situation.

Creating multiple sidebars in wordpress is a fairly easy process. We have to work just on functions.php file. Your default functions.php file should look like this:

<?php
if ( function_exists('register_sidebar') )
register_sidebar();
?>

To create two sidebars paste the following code on your functions.php file:

<?php
if ( function_exists('register_sidebar') )
register_sidebar(array('name'=>'sidebar1',
'before_widget' => '',
'after_widget' => '',
'before_title' => '<h4>',
'after_title' => '</h4>',
));
register_sidebar(array('name'=>'sidebar2',
'before_widget' => '',
'after_widget' => '',
'before_title' => '<h4>',
'after_title' => '</h4>',
));
?>

As you can see i’ve created two sidebars called sidebar1 and sidebar2. To use these sidebars paste on your php files the following code:

Sidebar1 code goes like this:
<?php if ( !function_exists('dynamic_sidebar')
|| !dynamic_sidebar('sidebar1') ) : ?>
<?php endif; ?>

Sidebar2 code goes like this:
<?php if ( !function_exists('dynamic_sidebar')
|| !dynamic_sidebar('sidebar2') ) : ?>
<?php endif; ?>

Hope you enjoy this.

  1. eJohnny
    March 20th, 2010
    7:26 pm

    this helped me a lot :)

  2. WP Themes
    August 14th, 2010
    4:22 am

    Good brief and this post helped me alot in my college assignement. Gratefulness you as your information.