is_active_sidebar example

<?php /** * Displays the footer widget area. * * @package WordPress * @subpackage Twenty_Twenty_One * @since Twenty Twenty-One 1.0 */

if ( is_active_sidebar( 'sidebar-1' ) ) : ?> <aside class="widget-area"> <?php dynamic_sidebar( 'sidebar-1' ); ?> </aside><!-- .widget-area --> <?php endif;
    $classes[] = 'no-js';

    // Adds `singular` to singular pages, and `hfeed` to all other pages.     $classes[] = is_singular() ? 'singular' : 'hfeed';

    // Add a body class if main navigation is active.     if ( has_nav_menu( 'primary' ) ) {
        $classes[] = 'has-main-navigation';
    }

    // Add a body class if there are no footer widgets.     if ( ! is_active_sidebar( 'sidebar-1' ) ) {
        $classes[] = 'no-widgets';
    }

    return $classes;
}
add_filter( 'body_class', 'twenty_twenty_one_body_classes' );

/** * Adds custom class to the array of posts classes. * * @since Twenty Twenty-One 1.0 * * @param array $classes An array of CSS classes. * @return array */
Home | Imprint | This part of the site doesn't use cookies.