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.

I am making sidebars for my theme using the register sidebar function. The codex does it something like this

if ( function_exists('register_sidebar') )
register_sidebar(array(
'name' => 'Right Sidebar',
'id' => 'right-sidebar',
'before_widget' => '<li id="%1$s" class="widget %2$s">',
'after_widget' => '</li>',
'before_title' => '<h4>',
'after_title' => '</h4>',
));

however Jason Tadlock does it something like this:

if ( function_exists('register_sidebar') )
register_sidebar(array(
'name' => 'Right Sidebar',
'id' => 'right-sidebar',
'before_widget' => '<div>',
'after_widget' => '</div>',
'before_title' => '<h4>',
'after_title' => '</h4>',
));

ie that (causes the dynamic_sidebar function to ) output 
<ul><div> ... etc ... </div><div> ... etc ... </div></ul> 
using no <li> tags becuase of the before and after widget paramaters

I have found nothing on the w3c that allows anything other than < li > tags inside < ul > tags, but yet I cant imagine Justin Tadlock endorsing invlaid code.

To be honest Justin's way makes a bit more sense to me semantically but I'm sure others would differ. My questions are - is it ok to do it this way? .... and which is best ?

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

dynamic_sidebar() does not output a <ul>, so what your code should look like is as follows:

<div id="sidebar">
    <?php dynamic_sidebar(); ?>
</div>

and that, along with <div> tags in before_widget and after_widget, will give you nested divs.

share|improve this answer
    
Yes I see now I had thought that the UL was generated by wordpress but I must have been looking via firebug when I looked closer at the actual file I see it was actually in my code around dynamic_sidebar. Thanks, that explains it. –  byronyasgur Jan 21 '12 at 2:20
add comment

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.