is_active_sidebar() WordPress Function

The is_active_sidebar() function is used to check if a sidebar is active and has widgets. It returns a Boolean value (true/false).

is_active_sidebar( string|int $index ) #

Determines whether a sidebar contains widgets.


Description

For more information on this and similar theme functions, check out the Conditional Tags article in the Theme Developer Handbook.


Top ↑

Parameters

$index

(string|int)(Required)Sidebar name, id or number to check.


Top ↑

Return

(bool) True if the sidebar has widgets, false otherwise.


Top ↑

Source

File: wp-includes/widgets.php

function is_active_sidebar( $index ) {
	$index             = ( is_int( $index ) ) ? "sidebar-$index" : sanitize_title( $index );
	$sidebars_widgets  = wp_get_sidebars_widgets();
	$is_active_sidebar = ! empty( $sidebars_widgets[ $index ] );

	/**
	 * Filters whether a dynamic sidebar is considered "active".
	 *
	 * @since 3.9.0
	 *
	 * @param bool       $is_active_sidebar Whether or not the sidebar should be considered "active".
	 *                                      In other words, whether the sidebar contains any widgets.
	 * @param int|string $index             Index, name, or ID of the dynamic sidebar.
	 */
	return apply_filters( 'is_active_sidebar', $is_active_sidebar, $index );
}


Top ↑

Changelog

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