Add a new sidebar or widget area to a classic theme, ready to fill from Appearance > Widgets.
add_action( 'widgets_init', function (): void {
register_sidebar( [
'name' => 'Shop sidebar',
'id' => 'nahnu-shop-sidebar',
'description' => 'Shown next to products on shop pages.',
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
] );
} );
// Then show it in a template file:
// if ( is_active_sidebar( 'nahnu-shop-sidebar' ) ) {
// dynamic_sidebar( 'nahnu-shop-sidebar' );
// }
Always add PHP to a staging site first, or have FTP or file manager access ready, so you can undo it if something goes wrong.
Widget areas let non-developers change part of a page from Appearance → Widgets. If your classic theme doesn’t have one where you need it, this snippet registers a new one.
register_sidebar() runs on widgets_init and creates the widget area. The before_widget and before_title settings control the HTML around each widget; %1$s and %2$s are replaced with the widget’s id and classes.
To show the widgets, call dynamic_sidebar() with the same id in a template file, such as your child theme’s sidebar or WooCommerce template.
Go to Appearance → Widgets. “Shop sidebar” should be listed.