wp_get_sidebar() WordPress Function

The wp_get_sidebar() function is used to retrieve the sidebar name for the current page template. The sidebar name is set in the WordPress admin panel under Appearance > Widgets.

wp_get_sidebar( string $id ) #

Retrieves the registered sidebar with the given ID.


Parameters

$id

(string)(Required)The sidebar ID.


Top ↑

Return

(array|null) The discovered sidebar, or null if it is not registered.


Top ↑

Source

File: wp-includes/widgets.php

function wp_get_sidebar( $id ) {
	global $wp_registered_sidebars;

	foreach ( (array) $wp_registered_sidebars as $sidebar ) {
		if ( $sidebar['id'] === $id ) {
			return $sidebar;
		}
	}

	if ( 'wp_inactive_widgets' === $id ) {
		return array(
			'id'   => 'wp_inactive_widgets',
			'name' => __( 'Inactive widgets' ),
		);
	}

	return null;
}


Top ↑

Changelog

Changelog
VersionDescription
5.9.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.