wp_find_widgets_sidebar

The timeline below displays how wordpress function wp_find_widgets_sidebar has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 5.9

/**
 * Finds the sidebar that a given widget belongs to.
 *
 * @since 5.8.0
 *
 * @param string $widget_id The widget ID to look for.
 * @return string|null The found sidebar's ID, or null if it was not found.
 */
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;
}

WordPress Version: 5.8

/**
 * Finds the sidebar that a given widget belongs to.
 *
 * @since 5.8.0
 *
 * @param string $widget_id The widget id to look for.
 * @return string|null The found sidebar's id, or null if it was not found.
 */
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;
}