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

My question is concerning dynamic sidebars and wrapping the dynamic sidebar code in the <ul> tag.

When I have widgets/dynamic sidebar enabled do not add widgets to the sidebar, and do not wrap the dynamic sidebar php code in the <ul> tag my theme it is XHTML valid. But when I add a widget it is invalid and requires the <ul> tag to make it valid! How do I make it valid in all circumstances?

<?php if ( !function_exists('dynamic_sidebar')
        || !dynamic_sidebar() ) : ?>
<?php endif; ?>
share|improve this question
up vote 3 down vote accepted

I've had similar issues in the past with custom sidebars. It was caused by the improper use of the <ul> and <li> tags. I was adding them in the sidebar.php file and not inside the function. Now I use this code and with 6 active widgets I have no errors. Take a look at the code and let me know if you have any questions:


  if (!function_exists( 'ideatree_widgets_init' )) {
   function ideatree_widgets_init() {
      'name' => __( 'Primary Widget Area', 'ideatree' ), 
      'id' => 'primary-widget-area', 
      'description' => 'The primary widget area', 'ideatree', 
      'before_widget' => '<ul><li id="%1$s" class="widget-container %2$s">', 
      'after_widget' => '</li></ul>', 
      'before_title' => '<h3 class="widgettitle">', 
      'after_title' => '</h3>',)
      'name' => 'Secondary Widget Area', 'ideatree', 
      'id' => 'secondary-widget-area', 
      'description' => 'The secondary widget area', 'ideatree', 
      'before_widget' => '<ul><li id="%1$s" class="widget-container %2$s">', 
      'after_widget' => '</li></ul>', 
      'before_title' => '<h3 class="widgettitle">', 
      'after_title' => '</h3>',)

    add_action('widgets_init', 'ideatree_widgets_init');


<div class="wrapper sidebar">
  <div id="upper-sidebar">
    <?php if ( ! dynamic_sidebar( 'primary-widget-area' ) ) : ?>
    <?php endif; ?>
  </div><!-- END UPPER-SIDEBAR -->
  <div id="lower-sidebar">
    <?php if ( ! dynamic_sidebar( 'secondary-widget-area' ) ) : ?>
    <?php endif; ?>
  </div><!-- END LOWER-SIDEBAR -->
</div><!-- END SIDEBAR -->
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.