Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

1 Answer 1

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:

functions.php

<?php
  // REGISTER THE SIDBARS
  if (!function_exists( 'ideatree_widgets_init' )) {
   function ideatree_widgets_init() {
    register_sidebar(array(
      '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>',)
      );
    register_sidebar(array(
      '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');
    }
  ?>

sidebar.php

<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

 
discard

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.