Example 1 — Print a sidebar only when it has widgets
Show the sidebar box only if the site owner added widgets.
<?php if ( is_active_sidebar( 'sidebar-1' ) ) : ?>
<aside class="widget-area">
<?php dynamic_sidebar( 'sidebar-1' ); ?>
</aside>
<?php endif; ?> How It Works
is_active_sidebar( 'sidebar-1' )returns true or false.- When it is true, WordPress prints the
asideand the widgets. - When it is false, the whole block is skipped.

