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 theme creates several widget areas for the end user. However, I've got a slight problem in that, if multiple widgets are dropped onto any sidebar container, the resulting code in "view source" is not wrapped in a single container div.

For example, here's what it looks like

Start of a single widget container:

<div class="name-of-my-widget">
    <h4>Widget title</h4>
    <div class="textwidget">
        contents of widget 1

<div class="name-of-my-widget">
    <h4>Widget title</h4>
    <div class="textwidget">
        contents of widget 2

What do I need to do to the way I'm creating this widget so that a single wrapper div encloses all of the widgets added to the container?

if ( function_exists('register_sidebar') )
    'name' => 'Inside Header Area',
    'id' => 'inside-header-widget',
    'before_widget' => '<div class="test-sidebar  %2$s">',
    'after_widget' => '</div>', 
    'before_title' => '<h4>',
    'after_title' => '</h4>',
share|improve this question
up vote 2 down vote accepted

Sidebar functionality doesn't handle wrapping container, you need to add that on template level. Here is example markup of sidebar-primary.php template (taken from Hybrid theme and simplified a bit):

if ( is_active_sidebar( 'primary' ) ) : ?>

    <div id="primary" class="sidebar aside">

        <?php dynamic_sidebar( 'primary' ); ?>

    </div><!-- #primary .aside -->

<?php endif; ?>

Also I highly recommend Justin's Sidebars in WordPress tutorial.

share|improve this answer
Thanks Rarst. Exactly what I was looking for. – Scott B Dec 18 '10 at 16:11

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.