wp_find_widgets_sidebar( string $widget_id ): string|null

In this article

Finds the sidebar that a given widget belongs to.

Parameters

$widget_idstringrequired
The widget ID to look for.

Return

string|null The found sidebar’s ID, or null if it was not found.

Source

function wp_find_widgets_sidebar( $widget_id ) {
	foreach ( wp_get_sidebars_widgets() as $sidebar_id => $widget_ids ) {
		foreach ( $widget_ids as $maybe_widget_id ) {
			if ( $maybe_widget_id === $widget_id ) {
				return (string) $sidebar_id;
			}
		}
	}

	return null;
}

Changelog

VersionDescription
5.8.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.