A widget area (also called a "sidebar" in the WordPress API, regardless of where it's actually placed on the page) is a region a theme defines, that an editor can then fill with content blocks from the WordPress admin — without touching any code.
// functions.php
function wgh_register_sidebars() {
register_sidebar([
'name' => 'Blog Sidebar',
'id' => 'blog-sidebar',
'before_widget' => '<div class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
]);
}
add_action('widgets_init', 'wgh_register_sidebars');Wrapped in a check for whether the area actually has any widgets placed in it — an empty sidebar shouldn't render an empty wrapper element.
<?php if (is_active_sidebar('blog-sidebar')) : ?>
<aside class="sidebar">
<?php dynamic_sidebar('blog-sidebar'); ?>
</aside>
<?php endif; ?>Every widget an editor drags into this area gets automatically wrapped in the HTML defined by these four settings — a consistent container and heading structure without the theme needing to know in advance which widgets will be used.
function wgh_register_sidebars() {
register_sidebar(['name' => 'Blog Sidebar', 'id' => 'blog-sidebar']);
register_sidebar(['name' => 'Footer Column 1', 'id' => 'footer-1']);
register_sidebar(['name' => 'Footer Column 2', 'id' => 'footer-2']);
}
add_action('widgets_init', 'wgh_register_sidebars');Widgets and the block editor
Since WordPress 5.8, a widget area can also hold blocks (the same block editor used for post content), not just the older classic widgets — register_sidebar() itself is unchanged either way.