Reputation: 958
I'm trying to get a list with all registered sidebars using $wp_registered_sidebars but it returns an empty array.
Here is my code:
foreach ($GLOBALS['wp_registered_sidebars'] as $sidebar)
{
$sidebar_options[$sidebar['id']] = $sidebar['name'];
}
It returns Array()
In a page template it works, but not in my functions.php
Any idea? Thanks
Upvotes: 1
Views: 1806
Reputation: 3358
add the following function in your theme functions.php
<?php
function my_sidebar_selectbox( $name = '', $current_value = false ) {
global $wp_registered_sidebars;
if ( empty( $wp_registered_sidebars ) )
return;
foreach ( $wp_registered_sidebars as $sidebar ) :
echo $sidebar['name'];
endforeach;
}
?>
and call it as my_sidebar_selectbox();
it is working to me
Upvotes: 0
Reputation: 3358
put this function in your theme functions.php
function get_my_widgets()
{
foreach ($GLOBALS['wp_registered_sidebars'] as $sidebar)
{
$sidebar_options[$sidebar['id']] = $sidebar['name'];
}
}
add_action('init','get_my_widgets');
and call this function as usual as get_my_widgets();
to get the registered sidebar list
Upvotes: 3