Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get all WordPress sidebars

I'm trying to get a list with all registered sidebars using $wp_registered_sidebars but the global variable returns an empty array.

function get_sidebars() {

    global $wp_registered_sidebars;

    $sidebar_options = array();

    foreach ($wp_registered_sidebars as $sidebar)
    {
        $sidebar_options[$sidebar['id']] = $sidebar['name'];
    }

    return $sidebar_options;

}


$fields['sidebar_settings'] = array(
    'active' => array(
        ...
        'values' => get_sidebars(),
        ...
    ),
);

Why is the global variable empty and is there another way to store all registered sidebars in an array?

like image 906
dollseb Avatar asked Jul 12 '14 01:07

dollseb


1 Answers

Please try this

https://wordpress.stackexchange.com/questions/13450/list-all-sidebar-names

you get all the sidebar name lists

like image 59
Ritesh d joshi Avatar answered Oct 04 '22 08:10

Ritesh d joshi