Get the list of gadgets in the specified sidebar

WordPress development comment sixteen Reading mode

The following code can be used to obtain the list of gadgets in the specified sidebar.

 function get_widget_ids_in_sidebar($sidebar_id) { $widget_ids = array(); //Get the list of gadgets in the specified sidebar $widgets = wp_get_sidebars_widgets(); if (isset($widgets[$sidebar_id])) { $widget_ids = $widgets[$sidebar_id]; } return $widget_ids; } //Output widget numbers in the sidebar $sidebar_id = 'sidebar'; //  ID of the sidebar $widget_ids = get_widget_ids_in_sidebar($sidebar_id); //Traverse the widget list and output the widget number foreach ($widget_ids as $widget_id) { Echo "Widget No.: $widget_id<br>"; }

 

Most of the articles on this site are original and used for personal learning records, which may be helpful to you, for reference only!

 weinxin
My Wechat
Copyright Notice
Please indicate the source and link of the original article reprinted on this site. Thank you for your cooperation!
five hundred and ninety-eight million eight hundred and forty-five thousand and six
 
 Robin
five hundred and ninety-eight million eight hundred and forty-five thousand and six
 anonymous

Comment

Anonymous netizens
 :?:  :razz:  :sad:  :evil:  :!:  :smile:  :oops:  :grin:  :eek:  :shock:  :???:  :cool:  :lol:  :mad:  :twisted:  :roll:  :wink:  :idea:  :arrow:  :neutral:  :cry:  :mrgreen:

Drag the slider to complete validation