Forums
Forums / Themes and Templates / Count widgets in sidebar
(@q-styler)
15 years, 11 months ago
Hi! I’m looking for a way to count a number of a widgets that has sidebar to make my theme more dynamic. Didn’t find any references in codex and in google. Is there any way to do it?
Thank you!
(@michaelh)
The Right Now module in the dashboard uses this:
if ( !empty($wp_registered_sidebars) ) { $sidebars_widgets = wp_get_sidebars_widgets(); $num_widgets = 0; foreach ( (array) $sidebars_widgets as $k => $v ) { if ( 'wp_inactive_widgets' == $k ) continue; if ( is_array($v) ) $num_widgets = $num_widgets + count($v); } $num = number_format_i18n( $num_widgets );
See wp-admin/includes/dashboard.php
Thank you! That helped somehow 🙂
The topic ‘Count widgets in sidebar’ is closed to new replies.