wp_find_widgets_sidebar() WordPress Function

The wp_find_widgets_sidebar() function is used to search for a sidebar by its name or id. It returns an array of sidebar data (name, id, description, class, before_widget, after_widget, before_title, and after_title) if the sidebar is found. If the sidebar is not found, an empty array is returned.

wp_find_widgets_sidebar( string $widget_id ) #

Finds the sidebar that a given widget belongs to.


Parameters

$widget_id

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


Top ↑

Return

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


Top ↑

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
VersionDescription
5.8.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.