<?php if ( is_active_sidebar( 'your-sidebar-slug' ) ) { ?>
<ul id="sidebar">
<?php dynamic_sidebar('your-sidebar-slug'); ?>
</ul>
<?php } ?>
//in functions.php
function wpdocs_theme_slug_widgets_init()
{
register_sidebar(array(
'name' => 'Main Sidebar',
'id' => 'sidebar-1',
'description' => 'Widgets in this area will be shown on all posts and pages.',
'before_widget' => '<li id="%1$s" class="widget %2$s">',
'after_widget' => '</li>',
'before_title' => '<h2 class="widgettitle">',
'after_title' => '</h2>',
));
}
add_action('widgets_init', 'wpdocs_theme_slug_widgets_init');
//got to appearance->widgets and add widgets
//in sidebar.php
<?php if (!is_active_sidebar('sidebar-1')) {
return;
}
?>
<div class="col-md-3 widget-area" id="secondary" role="complementary">
<?php dynamic_sidebar('sidebar-1'); ?>
</div><!-- #secondary -->