How to Create Multiple Dynamic Sidebars for WordPress Widgets

In the last tutorial, you learnt how to widgetize your wordpress theme to support wordpress widgets. Now this tutorial explains how to create multiple dynamic sidebars to add various combinations of widgets to customize your wordpress theme even more.

I suggest you read how to Widget-Enable WordPress Themes in 3 Easy Steps before reading further as examples will be quoted in the same context.

Edit Functions.php for Multiple Dynamic Sidebars

The functions.php code which helped to widgetize your wordpress theme and support a single dynamic sidebar, now needs to be edited (using any text editor like Notepad) to support multiple sidebars. You remember we had modified the default function.php from

if ( function_exists('register_sidebar') )

to the new code below to support our customized template with h4 subtitles and non-default unordered lists in the sidebar. REMEMBER you need to edit functions.php to match your wordpress theme or it will not work.

if ( function_exists('register_sidebar') )
'before_widget' => '',
'after_widget' => '',
'before_title' => '<h4>',
'after_title' => '</h4>',

To support multiple sidebars, I simply need to specify that multiple sidebars be used and name them as I like. In our case I use Sidebar1, Sidebar2 etc and as many as you like. The code now looks like this –

if ( function_exists('register_sidebar') )
'before_widget' => '',
'after_widget' => '',
'before_title' => '<h4>',
'after_title' => '</h4>',
'before_widget' => '',
'after_widget' => '',
'before_title' => '<h4>',
'after_title' => '</h4>',

I personally have extended this capacity to 6 dynamic sidebars on this blog. Here is how it looks like on top of admin panel.

4 Dynamic Widget Sidebars
Now you can drag and drop widgets of your choice to different sidebars and customize the options. Remember to Save Changes or else all customization is lost.

Add Dynamic Sidebars to WordPress Template

Now you need to place the code in the wordpress theme template where you want the relevant wordpress widgets to work. Instead of the previous code, you can place the different dynamic sidebars in different areas of the template.

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; ?>

Save the template and watch your widgets go live. You can add lots of dynamic sidebars with various widget combinations and have truly unique web design concept.

77 comments on “How to Create Multiple Dynamic Sidebars for WordPress Widgets

  1. Hannit says:

    Very clear article.

    In order to make this really usable I’d add the following plugin:

    This plugin lets you duplicate existing widgets so you can use more then one instance of them. Can be very useful in case you want to have some common functionality on the sidebars.

  2. David Stembridge says:

    On my template, the call for sidebar is:

    I registered a new sidebar successfully; but when I add the call for new sidebar as you suggested…

    I get a oddly formated page.
    I am adding the code to a very slightly modified page template. Any ideas, or clues?

  3. David Stembridge says:

    OK… I modified the base page, rather than a tweaked page, and that works. The formating seems a little off though, from the main page I’m working on:
    I have been tweaking on a second WP install here:
    Going back and forth, the heading for the new sidebars doesn’t look the same. Is that because I’m using the h4 subtitles? Why are you suggesting the header change?
    Thanks again!

  4. QuickOnlineTips says:

    David – it is indeed a h2 vs h4 issue. Customize it as per your own site CSS.

  5. Rafael Dourado says:

    Nice article! Just to complement what you said… The function dynamic_sidebar accept numbers too, like 1 for the first sidebar and 2 for the second. I prefer using numbers, because sometimes I change the sidebar name for some users understand it.

  6. Jason Kelley says:

    I added 7 new sidebars to functions.php file within my current theme but do not see any additional sidebars in the wordpress admin. Any thoughts…

  7. QuickOnlineTips says:

    Check under the widgets tab. Remember to name them differently.

  8. David Glendinning says:

    Have added an additional sidebar called sidebar2 to the functions.php file and can see it OK in the widgets admin. However I am having a problem getting the new sidebar to execute. What is the correct format for to get ‘sidebar2’ to execute in the template.

  9. Sounds Good says:

    Thank you!! Simply, clean, great post!

  10. Rajeef says:

    Can you explain one thing — how do you make your page call your new sidebars? I mean, I would like to call my second sidebar as the “right column”.

    Do I have to edit my template pages?



  11. QuickOnlineTips says:

    The dynamic sidebar template codes have to be inserted into the sidebar.php in your blog template. Otherwise how will it know where the code has to be executed. :-)

  12. jbj says:

    Great tutorial, thanks, I was looking for something like this !

  13. sailor says:

    As an amateur PHP programmer struggling to get my own site developed, I found this article to be of great assistance. Without this I would still have been struggling to figure this lot out. Thanks.

  14. Web-Betty says:


    I found this article to be incredibly helpful, however, I’m having trouble with the headers in my second sidebar (which is actually at the very bottom of the page). You can see the “Calendar” but the title does not style with the like it should. The titles in the right sidebar are correct. I’m using for the titles and I’ve confirmed that my functions.php calls for . Can you assist?


  15. nasirJumani says:

    I have got my dynamic sidebars widgetized in no time. Thanks alot! :)

  16. zacheos says:

    Some people use a hierarchy method in the naming of the template files to achieve multiple WordPress sidebars, but in my opinion it is too cumbersome for most userís needs. The method of multiple sidebars for WordPress that I use involves only a very simple PHP snippet added to the template to call the desired sidebar file depending on the area of the site that you are in.

    • crush says:

      Thank you so much! I just have 2 sidebars now. But… I still need the ‘very simple PHP snippet… to call the desired sidebar file depending on the area of the site’.

      I would like to see different sidebars on different pages. Any PHP snippet available?

      • QuickOnlineTips says:

        You can easily different sidebars on pages, single posts, index pages, archives, categories, etc.

  17. Andrew says:

    Many thanks for this article– I went from scratching my head to 10 sidebars in 20 minutes.

  18. lonchbox says:

    Thanx, great post

  19. Buck Wilson says:


    You should probably put both calls to register_sidebar within your if statement:

    ‘before_widget’ => ”,
    ‘after_widget’ => ”,
    ‘before_title’ => ”,
    ‘after_title’ => ”

    ‘before_widget’ => ”,
    ‘after_widget’ => ”,
    ‘before_title’ => ”,
    ‘after_title’ => ”

    Otherwise the function will bomb if register_sidebar doesn’t exist for any reason. If you’re not worried about this, then omit the “if” statement altogether. However, just wrapping it around one call won’t help.

    Thanks for the post!

  20. mia says:

    Thank you so much for saving my day! :D

  21. Shannon says:

    Thanks for sharing this! My php knowledge is rudimentary, and this was a huge help. You saved me much time trying to figure out the problem with my template’s sidebars. I did run into an error updating this through the theme editor. Had to do it offline and ftp the files back up. Worked wonderfully.

  22. sbs ba?vurular? says:

    I was searching like this. Mia said ” you saved her day” I agree Mia

  23. Chais Meyer says:

    Thank you very much for this! Many hours saved and the wife will appreciate that. I am now looking for a way to call one of my 10 sidebars dynamically inside the wp admin without having to change my code in my template per page. whooo…that was a long sentence.

    If you have any tips in this area, I would love to hear about it.
    ~ Chais Meyer

  24. Prabhjeet Singh says:

    Another great article. CHEERS..! Just what i was looking for. And believe it took only 5 minutes to do this task. Really thanks…

  25. Maxim says:

    Thank you for this post. It helped me to save a lot of time. I was looking for the way to duplicate existing sidebars and finally found useful piece of information only here.

  26. Mike West says:

    Cool, it works perfect !! Thank you very much for your work ! But, wordpress is putting automaticly to the right side, to the other sidebar, and i wanted it to the left side of my site, how can i do this ? Thank you !

  27. Info Gaptek says:

    I found this page by googling.
    Thanks for posting this tips!

  28. Mark says:

    As I learn more I will always remember that I started here. Thank you for all the info I can put it to use in my business plan.

  29. Wayne says:

    Thank you so mutch I have tried every so called webmasters code and nothing worked, Why can’t anybody keap things simple like you! And show you what you need to do… 5 Stars

  30. weevie833 says:

    For each instance of sidebars that I have added, how would I go about defining which category IDs to include/exclude from each instance? I had originally defined the global exclusion IDs in the default-widget.php file prior to adding additional sidebar instances, but now I want to defeat that and include/exclude on specific instances of sidebars 1,2,3, etc. – thx – weevie833

Leave a Reply

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

All comments moderated. Use True name. No irrelevant links. Post useful content.