I’ve never gotten is_active_sidebar()
to work, no matter if there’s widgets in the sidebar or not I always get false returned. Currently I’m creating a sidebar for each top level page:
I create my own widget(s):
And I’m testing whether the sidebar is active like so:
if(is_active_sidebar(get_the_title()))
echo 'active';
else
echo 'not active';
Even when I manually put the title in: is_active_sidebar('Test');
it always returns false. Am I using the conditional wrong? Do I need to add some sort of setting? Why would is_active_sidebar()
fail?
The
is_active_sidebar('Test');
function works correctly if the correct slug is used.I think that the problem is that you are constructing the sidebar ID like this:
Then prepending
sidebar-
to it …But you are using the unmodified title as the slug when you check …
You need to alter your code that you are checking for the correct sidebar slug. you need to be consistent.
Edit: As stated, the “function works correctly if the correct slug is used”. While the Codex does state that the “Name” is a valid parameter value, using the name does not work, at least not when I try to use it. Proof of concept (mostly copied from the Codex):
With a sidebar registered with the above code, and a widget in the sidebar, the following returns
false
.While using the ID returns the correct result–
true
:I have not done enough research to determine whether the Codex is wrong, or whether there is a bug in the Core. However, using un-normalized data like a post name is probably a bad idea in either case.