is_active_sidebar( string|int $index )
Determines whether a sidebar is in use.
Description Description
For more information on this and similar theme functions, check out the Conditional Tags article in the Theme Developer Handbook.
Parameters Parameters
- $index
-
(string|int) (Required) Sidebar name, id or number to check.
Return Return
(bool) true if the sidebar is in use, false otherwise.
Source 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 ); }
Expand full source code Collapse full source code View on Trac
Changelog Changelog
Version | Description |
---|---|
2.8.0 | Introduced. |
User Contributed Notes User Contributed Notes
You must log in before being able to contribute a note or feedback.
Example
Display different output depending on whether the sidebar is active or not.
In the description: “in use” means that the sidebar contains widgets.
Any sidebar that contains widgets will return TRUE, whereas any sidebar that does not contain any widgets will return FALSE.
Note that you cannot search by sidebar name if the ID was not specifically declared when register_sidebar was called, and even then only when the ID is exactly the value of
sanitize_title($sidebar_name)
.The simple method used by the code (see above) is the reason for this: