is_dynamic_sidebar()WP 2.2.0

Whether the dynamic sidebar is enabled and used by theme.

For more information on this and similar theme functions, check out the Conditional Tags article in the Theme Developer Handbook.

No Hooks.

Return

true|false. True if using widgets, false otherwise.

Usage

is_dynamic_sidebar();

Notes

  • Global. Array. $wp_registered_widgets Registered widgets.
  • Global. Array. $wp_registered_sidebars Registered sidebars.

Changelog

Since 2.2.0 Introduced.

Code of is_dynamic_sidebar() WP 5.9.3

function is_dynamic_sidebar() {
	global $wp_registered_widgets, $wp_registered_sidebars;

	$sidebars_widgets = get_option( 'sidebars_widgets' );

	foreach ( (array) $wp_registered_sidebars as $index => $sidebar ) {
		if ( ! empty( $sidebars_widgets[ $index ] ) ) {
			foreach ( (array) $sidebars_widgets[ $index ] as $widget ) {
				if ( array_key_exists( $widget, $wp_registered_widgets ) ) {
					return true;
				}
			}
		}
	}

	return false;
}