函数原型
is_active_sidebar( string|int $index ): bool
函数描述
Determines whether a sidebar contains widgets.
是否弃用
未弃用
函数参数
-
$index
string|int
Required - Sidebar name, id or number to check.
函数返回值
bool True if the sidebar has widgets, false otherwise.
函数位置
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 );
}
源码链接
变更日志
| Version | Description |
|---|---|
| 2.8.0 | Introduced. |

