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:
$sidebarID = preg_replace("/[\s_]/", "-", strtolower($page->post_title));
Then prepending sidebar-
to it …
register_sidebar(array(
'name' => $page->post_title,
'id' => 'sidebar-'.$sidebarID,
//
But you are using the unmodified title as the slug when you check …
if(is_active_sidebar(get_the_title()))
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):
$args = array(
'name' => 'My Sidebar',
'id' => 'my-sidebar-id',
'description' => '',
'class' => '',
'before_widget' => '<li id="%1$s" class="widget %2$s">',
'after_widget' => '</li>',
'before_title' => '<h2 class="widgettitle">',
'after_title' => '</h2>'
);
register_sidebar($args);
With a sidebar registered with the above code, and a widget in the sidebar, the following returns false
.
var_dump(is_active_sidebar('My Sidebar'));
While using the ID returns the correct result– true
:
var_dump(is_active_sidebar('my-sidebar-id'));
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.