Problem adding sidebar to Underscores theme
I have been struggling with this for hours now, any help appreciated. I am using Underscores theme with one sidebar (sidebar-1, on the left) and Custom Sidebars plugin so that I can have different side content on each page. The problem is when I add a new sidebar (sidebar-2) which I want to appear just above the footer to contain the same content on every page.
functions.php:
function myunderscores3_widgets_init() {
register_sidebar( array(
'name' = esc_html__( 'Sidebar', 'myunderscores3' ),
'id' = 'sidebar-1',
'description' = esc_html__( 'Add widgets here.', 'myunderscores3' ),
'before_widget' = 'section id="%1$s" class="widget %2$s"',
'after_widget' = '/section',
'before_title' = 'h2 class="widget-title"',
'after_title' = '/h2',
//'before_title' = '!--',
//'after_title' = '--',
) );
register_sidebar( array(
'name' = esc_html__( 'Bottom Sidebar', 'myunderscores3' ),
'id' = 'sidebar-2',
'description' = esc_html__( 'Add widgets here.', 'myunderscores3' ),
'before_widget' = 'section id="%1$s" class="widget %2$s"',
'after_widget' = '/section',
'before_title' = 'h2 class="widget-title"',
'after_title' = '/h2',
//'before_title' = '!--',
//'after_title' = '--',
) );
}
add_action( 'widgets_init', 'myunderscores3_widgets_init' );
sidebar.php (for the sidebar-1 content):
if ( ! is_active_sidebar( 'sidebar-1' ) ) {
return;
}
?
aside id="secondary" class="widget-area"
?php dynamic_sidebar( 'sidebar-1' ); ?
/aside!-- #secondary --
page.php (to pull in sidebar-1):
?php
get_sidebar();
?
/div!-- wrapper --
footer.php (to pull in sidebar-2):
if (is_active_sidebar( 'sidebar-2' )) {
dynamic_sidebar( 'sidebar-2' );
}
?
/div!-- #content --
After adding widget content to sidebar-2 this is working fine on every page apart from the one page that has no sidebar-1 content. On this page the sidebar-2 content is appearing twice - on the bottom as expected and in sidebar-1 content area also ! Furthermore the 'no-sidebar' class is missing from the body. In the backend the sidebar-1 widgets are located through each individual page whereas the sidebar-2 content is located through the widget ('As Sidebar for selected Post Types' - Pages). On the actual page where the sidebar-2 content is appearing twice I have not specified any sidebars inside the actual page as I am doing this through the widget settings. Any ideas ? Thank you