I want to have different sidebars on different pages.

So firstly I registered a few basic sidebars in functions.php. So they will be always there no matter where I move my theme. Let's name them Standard Sidebar, Special Sidebar, Tiny Sidebar.

The next step was creating sidebars metabox below posts and pages. It lists all the sidebars using foreach $GLOBALS['wp_registered_sidebars'] loop and allows user to pick one.

Now, here comes the trouble.

I don't know how to display my sidebars.

I have a meta value but get_sidebar() accepts only names from sidebar.php file.

What about registered (not included in sidebar.php) sidebars?

I know I could add all my sidebars to sidebar.php/save them as sidebar-name.php, but again, I'm going to use sidebar generator to add addtional sidebars to three basic ones.

Any ideas, walk-troughs how to accomplish this? Displaying registered sidebars by name will be a serious breakthrough in my case.

1 Answer 1


You can call registered sidebars with the dynamic_sidebar() function. Just put the ID of the sidebar in to the call. In the case below the id would be homepage-sidebar.

<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('homepage-sidebar') ) : ?><?php endif; ?>
  • 1
    dynamic_sidebar() is really old function by now, it's well time to stop checking if it exists. :) This just gets passed on as arcane spell...
    – Rarst
    Commented Apr 5, 2011 at 17:30
  • fair enough I've just had the snippet stored for a while and haven't bothered to change it. Commented Apr 5, 2011 at 20:05
  • Oh my God, I've been so blind ;/ In fact I found the same code @curtismchale gave in my own sidebar.php file... Just moved it from there to page.php... Thanks a lot guys, +1 :) Commented Apr 5, 2011 at 20:40
  • @Wordpressor rather than moving it to page.php you should stil call get_sidebar() and put your conditionals in sidebar.php.
    – Chris_O
    Commented Apr 6, 2011 at 8:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.