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

This is my function:

function ec_register_sidebars() { 
register_sidebars( 3, 
    'name' => 'Sidebar %d', 
    'id' => "sidebar-$i", 
    'before_widget' => '<li id="%1$s" class="widget %2$s">', 
    'after_widget' => '</li>', 
    'before_title' => '', 
    'after_title' => '' 

This does not work:

<?php if ( is_active_sidebar( 'Sidebar 1' ) ) : ?> 
<?php dynamic_sidebar( 'Sidebar 1' ); ?> 
    <?php else : ?> 
    No primary sidebar content 
<?php endif; ?>

BUT if I change the *is_active_sidebar* to 'Sidebar 2' or 'Sidebar 3', it works. For example, this works:

<?php if ( is_active_sidebar( 'Sidebar 2' ) ) : ?> 
<?php dynamic_sidebar( 'Sidebar 1' ); ?> 
    <?php else : ?> 
    No primary sidebar content 
<?php endif; ?>

I don't understand why this is. Any ideas?

share|improve this question

it looks like your name attribute is missing the sprintf aspect. that line should read

'name' => sprintf(__('Sidebar %d'), $i ),

otherwise %d doesn't reference $i at all. Also, it looks like you should be calling the sidebar id, not the name. The name is just for looks. For example, once the above is fixed, this coould work:

<?php dynamic_sidebar( 'sidebar-1' ); ?> 
share|improve this answer
It's still not working. Here is a url with a text file that comprises all the code involved: estevancarlos.kodingen.com/ecv7/ec_code.txt Here is an active page: estevancarlos.kodingen.com/ecv7/?projects=rada-2 – rpeg Jan 12 '12 at 20:31
You should not check the active sidebar by the index number, then activate it with the slug id. use one or the other. ie. <?php if ( is_active_sidebar( 'sidebar-1' ) ) : ?> <?php dynamic_sidebar( 'sidebar-1' ); ?>i would simplify the whole thing. also, don't generate all three sidebars in that one loop. add the three individually without the variables and %1$s complexity. look in the twentyten or twentyeleven theme and just copy exactly how they do it and modify it for your own. – dwenaus Jan 12 '12 at 20:48

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.