This guide will cover how to add a new widget area to a WordPress theme. This will enable you to add widgets to a chosen area of your WordPress website. Note that this differs from simply adding a widget to a pre-defined area, which can be done in the widget settings of your WordPress dashboard.
You should only perform this if you have experience editing WordPress PHP files.
Register a new widget area
Open your functions.php
file and add the following code:
function my_custom_widget_area() {
register_sidebar( array(
'name' => 'My Custom Widget Area',
'id' => 'custom-widget-area',
'before_widget' => '<div class="widget-area">',
'after_widget' => '</div>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
) );
}
add_action( 'widgets_init', 'my_custom_widget_area' );
You should edit the highlighted names to give your widget area a unique name and id.
Display widget area
The next step is to display your widget area in your chosen location.