Take the tour ×

This is my function:

function ec_register_sidebars() { 
register_sidebars( 3, 
    'name' => 'Sidebar %d', 
    'id' => "sidebar-$i", 
    '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 else : ?> 
    No primary sidebar content 
<?php endif; ?>

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

share|improve this question
add comment

1 Answer

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


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. –  Deryk Wenaus Jan 12 '12 at 20:48
add comment

Your Answer


