is_active_sidebar

Whether a sidebar is in use.

Description

is_active_sidebar( (string|int) $index ); 

Parameters (1)

0. $index (string|int)
Sidebar name, id or number to check.

Usage

  1. if ( !function_exists( 'is_active_sidebar' ) ) { 
  2. require_once ABSPATH . WPINC . '/widgets.php'; 
  3.  
  4. // Sidebar name, id or number to check. 
  5. $index = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = is_active_sidebar($index); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/widgets.php  
  1. function is_active_sidebar( $index ) { 
  2. $index = ( is_int($index) ) ? "sidebar-$index" : sanitize_title($index); 
  3. $sidebars_widgets = wp_get_sidebars_widgets(); 
  4. $is_active_sidebar = ! empty( $sidebars_widgets[$index] ); 
  5.  
  6. /** 
  7. * Filters whether a dynamic sidebar is considered "active". 
  8. * @since 3.9.0 
  9. * @param bool $is_active_sidebar Whether or not the sidebar should be considered "active". 
  10. * In other words, whether the sidebar contains any widgets. 
  11. * @param int|string $index Index, name, or ID of the dynamic sidebar. 
  12. */ 
  13. return apply_filters( 'is_active_sidebar', $is_active_sidebar, $index );