Register Extra Widget Areas
Creates additional widget areas, such as a shop sidebar or a blog sidebar, that you can fill under Appearance > Widgets and place with a shortcode or theme hook.
Opens WPIDE on
Code
// Widget area ID => name.
$wpide_extra_widget_areas = array(
'wpide-blog-sidebar' => 'Blog Sidebar',
'wpide-shop-sidebar' => 'Shop Sidebar',
);
add_action( 'widgets_init', function () use ( $wpide_extra_widget_areas ) {
foreach ( $wpide_extra_widget_areas as $id => $name ) {
register_sidebar( array(
'id' => $id,
'name' => $name,
'description' => sprintf( 'Show it with [widget_area id="%s"].', $id ),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
) );
}
} );
Notes
Add or rename areas in the list. Show them with [widget_area id="..."] from the Widget Area Shortcode snippet.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.