Register Multiple Sidebars in WordPress

Registering multiple sidebars for your WordPress blog/site allows you to use different widgets in different areas of your blog/site. In this example we will see how to register 2 sidebars and then use them in our template files.

In order to register your sidebars and then be able to access them from the menu Appearance → Widgets all you need to do is:

  1. Open your functions.php theme file (* create one if it doesn't exist)
  2. Copy and Paste the following code inside the  <php ?> tag:
    register_sidebars(2, array('name'=>'Sidebar %d'));
  3. Go to the menu Appearance → Widgets. Drag & drop the widgets you want from the available widgets to the Sidebar 1 and Sidebar 2 you have created.
  4. Depending on where you want the sidebar's widgets/content to appear open your corresponding theme file, for example your sidebar.php and copy and paste the following (*change the number to 2 if you want to display your second sidebar):
    <?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Sidebar 1') ) : ?>
    <?php endif; ?>

You can find more info on WordPress Sidebars here: codex.wordpress.org/Function_Reference/register_sidebars, codex.wordpress.org/Function_Reference/dynamic_sidebar

Tags: , ,

Author: Galadriel

Leave a Comment