WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
up vote 1 down vote accepted

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; ?>
share|improve this answer
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 Apr 5 '11 at 17:30
fair enough I've just had the snippet stored for a while and haven't bothered to change it. – curtismchale Apr 5 '11 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 :) – Wordpressor Apr 5 '11 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 Apr 6 '11 at 8:42

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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