Created
August 26, 2015 14:31
-
-
Save bdeleasa/f6fa966ff73bd57e6b27 to your computer and use it in GitHub Desktop.
Function for Wordpress that returns the number of active widgets in a sidebar.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Counts the number of widgets in a widget area. | |
* | |
* @param $sidebar_index string The id of the widget area | |
* @return int | |
*/ | |
function get_widgets_count( $sidebar_index ) { | |
global $wp_registered_sidebars; | |
$index = "{$sidebar_index}"; | |
$sidebars_widgets = wp_get_sidebars_widgets(); | |
if ( empty($wp_registered_sidebars[$index]) || !array_key_exists($index, $sidebars_widgets) || !is_array($sidebars_widgets[$index]) || empty($sidebars_widgets[$index]) ) | |
return 0; | |
return count( (array) $sidebars_widgets[$index] ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment