From the codex
is_active_sidebar( $index ); ?>
Parameters
$index
(mixed) (required) Sidebar name, id or number.
When i try any of my sidebar names it doesnt work; yet when I put in random numbers 1,2 and 3 guessing that my sidebars are numbered that way and it works, but this is not reliable. There is a trac issue about this and I suspect that there may be an issue with the function at the moment ( and also the example from twentyten in the codex seems to use a slug not a name) so what i want is a way of getting the sidebar’s name id or number as wordpress understands it.
EDIT ( this is the code i used to register the sidebar – i ended up adding the line ‘id’ => ‘right-sidebar’, after ‘name’ => etc to get the solution described below in the comment )
if ( function_exists('register_sidebar') )
register_sidebar(array(
'name' => 'Right Sidebar',
'before_widget' => '<li id="%1$s" class="widget %2$s">',
'after_widget' => '</li>',
'before_title' => '<h4>',
'after_title' => '</h4>',
));
2 Answers
Found a solution to the problem. I added a line of code id => ‘my-sidebar-id’ to the register_sidebar array so now i know the sidebar ID. There may be another way of doing it but this method seems to work fine for me now anyway.
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>',
));