Title: Variable sidebars &#8211; how to include them
Last modified: August 19, 2016

---

# Variable sidebars – how to include them

 *  [antoniop](https://wordpress.org/support/users/antoniop/)
 * (@antoniop)
 * [17 years, 9 months ago](https://wordpress.org/support/topic/variable-sidebars-how-to-include-them/)
 * I’m in the process of trying to get some variable sidebars with widgets enabled.
   I’ve defined the ‘widgetized’ sidebars in functions.php as show below. Below 
   I have two pieces of code, my modified functions.php and the code that decides
   what sidebar to load depending on what page is the current page. At this point
   I am totally lost. I’m not sure where to put the second piece of code or where
   to go from here.
 * FUNCTIONS.PHP
 *     ```
       <?php
       if ( function_exists('register_sidebar') )
       register_sidebar(array('name'=>'home',
       'before_widget' => '',
       'after_widget' => '',
       'before_title' => '<h4>',
       'after_title' => '</h4>',
       ));
   
       register_sidebar(array('name'=>'services',
       'before_widget' => '',
       'after_widget' => '',
       'before_title' => '<h4>',
       'after_title' => '</h4>',
       ));
   
       register_sidebar(array('name'=>'media',
       'before_widget' => '',
       'after_widget' => '',
       'before_title' => '<h4>',
       'after_title' => '</h4>',
       ));
   
       register_sidebar(array('name'=>'blog',
       'before_widget' => '',
       'after_widget' => '',
       'before_title' => '<h4>',
       'after_title' => '</h4>',
       ));
   
       register_sidebar(array('name'=>'contact',
       'before_widget' => '',
       'after_widget' => '',
       'before_title' => '<h4>',
       'after_title' => '</h4>',
       ));
   
       register_sidebar(array('name'=>'forum',
       'before_widget' => '',
       'after_widget' => '',
       'before_title' => '<h4>',
       'after_title' => '</h4>',
       ));
   
       ?>
       ```
   
 * and here is the code that I decides what ‘widgetized’ sidebar to load:
 *     ```
       <?php if ( is_front_page() ) { dynamic_sidebar('home'); } else { dynamic_sidebar('sidebar.php'); }
       	  elseif ( is_page(36) ) { dynamic_sidebar('services'); } else { dynamic_sidebar('sidebar.php'); }
       	  elseif ( is_page(42) ) { dynamic_sidebar('media'); } else { dynamic_sidebar('sidebar.php'); }
       	  elseif ( is_page(51) ) { dynamic_sidebar('blog'); } else { dynamic_sidebar('sidebar.php'); }
       	  elseif ( is_page(52) ) { dynamic_sidebar('contact'); } else { dynamic_sidebar('sidebar.php'); }
       	  elseif ( is_page(53) ) { dynamic_sidebar('forum'); } else { dynamic_sidebar('sidebar.php'); }
       ?>
       ```
   

The topic ‘Variable sidebars – how to include them’ is closed to new replies.

## Tags

 * [sidebar](https://wordpress.org/support/topic-tag/sidebar/)
 * [variable](https://wordpress.org/support/topic-tag/variable/)
 * [widgets](https://wordpress.org/support/topic-tag/widgets/)

 * 0 replies
 * 1 participant
 * Last reply from: [antoniop](https://wordpress.org/support/users/antoniop/)
 * Last activity: [17 years, 9 months ago](https://wordpress.org/support/topic/variable-sidebars-how-to-include-them/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
