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?

3 Answers 3


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

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

  • 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. Commented Sep 6, 2012 at 17:54
  • then you can create array, I updated my answer above
    – alexndm
    Commented Sep 6, 2012 at 18:01
  • will this just give me a selector to select a sidebar for that page? If so this is spot on! Commented Sep 6, 2012 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
    Commented Sep 6, 2012 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.'

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.