wp_find_widgets_sidebar( string $widget_id )

Finds the sidebar that a given widget belongs to.


Parameters Parameters

$widget_id

(string) (Required) The widget id to look for.


Top ↑

Return Return

(string|null) The found sidebar's id, or null if it was not found.


Top ↑

Source Source

File: wp-includes/widgets.php

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;
}


Top ↑

Changelog Changelog

Changelog
Version Description
5.8.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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