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 would like to do a dynamic sidebar for my WordPress site, so it would pull in the correct Sidebar template based on the page title of the page.

So if I had 10 sidebars all named like this:

Sidebar Template Name: About Sidebar Template Name: Contact Sidebar Template Name: Jobs Sidebar Template Name: Etc Sidebar Template Name: Page1

So the Sidebar 'About' would appear on the About page, and the same for contact, etc...

Any idea How I would do this? Or Is there an alternative way on how to do it?

share|improve this question

Something like this should work:

if( is_page() ) :
    $this_page = get_queried_object();
    if ( ! dynamic_sidebar( $this_page->post_title ) ) :
        echo 'No sidebar defined for this page title';
share|improve this answer

you can try to include different sidebars when creating new template

name a sidebar like sidebar-jobs.php then when creating template name: Jobs, just call this sidebar like so

<?php get_sidebar('jobs'); ?>

create metabox and list all registered sidebars

  <?php foreach ( $GLOBALS['wp_registered_sidebars'] as $sidebar ) { ?>
 <option value="<?php echo ucwords( $sidebar['id'] ); ?>">
          <?php echo ucwords( $sidebar['name'] ); ?>

then based on selected value - call selected sidebar

share|improve this answer
But then I will need a separate template for every separate sidebar page. I have 1 template, multiple pages which will have multiple sidebar templates. – Owen O'Neill Sep 6 '12 at 17:54
then you can create array, I updated my answer above – alexndm Sep 6 '12 at 18:01
will this just give me a selector to select a sidebar for that page? If so this is spot on! – Owen O'Neill Sep 6 '12 at 18:18
yes. it will. you need to make metabox for your page.php and place this <select> and that's it. I would recommend this metabox framework github.com/jaredatch/Custom-Metaboxes-and-Fields-for-WordPress I used it for displaying taxonomies and all pages inside metabox... works very well – alexndm Sep 6 '12 at 18:20

Here is a live example from one of my sites:

if(is_page('about-us')) {
if(is_page('contribute')) {
if(is_front_page() && is_page('about-us')) {
if(!is_front_page() && is_page('about-us')) {

if(is_category('archive')) {

You can see various scenarios where I need different widgets.

Also, in functions.php, I have this code:

if(function_exists('register_sidebar')) {
    register_sidebar(array('name' => 'Homepage Sidebar'));
    register_sidebar(array('name' => 'Blog Sidebar'));

        'name' => __('Main Sidebar'),
        'id' => 'main-sidebar',
        'description' => 'This sidebar is active on Homepage, Despre Noi, Directioneaza 2%, and individual profiles.'
        'name' => __('Archive Sidebar'),
        'id' => 'archive-sidebar',
        'description' => 'This sidebar is active on Archive page.'
share|improve this answer

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.