Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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>',
));
share|improve this question
1  
Just 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. –  byronyasgur Sep 6 '11 at 22:20
1  
Post this as answer and mark is as solution (allowed in 2 days) so this Q doesn't stay open. –  kaiser Sep 7 '11 at 8:36

2 Answers 2

up vote 3 down vote accepted

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>',
));
share|improve this answer

Straight from the php docBlock:

@param mixed $index Sidebar name, id or number to check

Hard to say anything if I don't see any code you used to register your sidebar.

share|improve this answer
    
I edited the post to include the code i originally had but as i was saying in the comment I found a solution which involved adding an extra line to this code. –  byronyasgur Sep 7 '11 at 1:53
    
I know 'name' is supposed to work too but it didnt do for me; whereas 'number' and 'id' worked fine. –  byronyasgur Sep 7 '11 at 2:04

Your Answer

 
discard

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.