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

Im trying to create like, 8 sidebar areas using an array of page templates (like date, archive, tag ect) and then looping through the array, creating a sidebar for each value.

I thought this should work, but it only creates a sidebar for the last value in the array:

$widget_areas = array('single','index','category','archive','tag','taxonomy','author','date','search','attachment');
foreach($widget_areas as $area){

        'name' => __( $area. ' Widgets' ),
        'id' => 'index',
        'description' => __( 'Widgets in this area will appear on the ' . $area ),
        'before_widget' =>'<div class="widget-container">',
        'before_title' => '<h3>',
        'after_title' => '</h3>',
        'after_widget' => '</div>'


The only sidebar it's creating is for the "attachment" template. What gives? Shouldnt register_sidebar run for each value in that array, creating a ton of sidebars? If I hardcode each section with register_sidebar that works, but I really dont want to repeat a bunch of code

share|improve this question
up vote 0 down vote accepted

Pass a different id for each sidebar or you will overwrite the same sidebar again and again. You can also just leave the id argument out, and WordPress will create one automatically.

Side note:

__( $area. ' Widgets' )


__( 'Widgets in this area will appear on the ' . $area )

… are wrong. The translation function expects a second parameter textdomain, and you cannot use a variable in the string that should be translated.

Use sprintf() with a placeholder to pass the variable, and use a context function to explain the parameter:

        '%s Widgets', 
        '%s = widget area name', 
share|improve this answer
I am not a smart, or careful person. I passed the $area variable to the description value but not the ID. Thanks for pointing that out and explaining the translation funtion – rugbert Jul 28 '13 at 14:23

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.