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.
Return
(string|null) The found sidebar's ID, or null if it was not found.
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; }
Expand full source codeCollapse full source codeView on TracView on GitHub
Changelog
Version | Description |
---|---|
5.8.0 | Introduced. |