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

$299 Affordable Web Design WordPress

This article was republished from its original source.
Call Us: 1(800)730-2416

Pixeldust is a 20-year-old web development agency specializing in Drupal and WordPress and working with clients all over the country. With our best in class capabilities, we work with small businesses and fortune 500 companies alike. Give us a call at 1(800)730-2416 and let’s talk about your project.

FREE Drupal SEO Audit

Test your site below to see which issues need to be fixed. We will fix them and optimize your Drupal site 100% for Google and Bing. (Allow 30-60 seconds to gather data.)

Powered by

Problem adding sidebar to Underscores theme

On-Site Drupal SEO Master Setup

We make sure your site is 100% optimized (and stays that way) for the best SEO results.

With Pixeldust On-site (or On-page) SEO we make changes to your site’s structure and performance to make it easier for search engines to see and understand your site’s content. Search engines use algorithms to rank sites by degrees of relevance. Our on-site optimization ensures your site is configured to provide information in a way that meets Google and Bing standards for optimal indexing.

This service includes:

  • Pathauto install and configuration for SEO-friendly URLs.
  • Meta Tags install and configuration with dynamic tokens for meta titles and descriptions for all content types.
  • Install and fix all issues on the SEO checklist module.
  • Install and configure XML sitemap module and submit sitemaps.
  • Install and configure Google Analytics Module.
  • Install and configure Yoast.
  • Install and configure the Advanced Aggregation module to improve performance by minifying and merging CSS and JS.
  • Install and configure Schema.org Metatag.
  • Configure robots.txt.
  • Google Search Console setup snd configuration.
  • Find & Fix H1 tags.
  • Find and fix duplicate/missing meta descriptions.
  • Find and fix duplicate title tags.
  • Improve title, meta tags, and site descriptions.
  • Optimize images for better search engine optimization. Automate where possible.
  • Find and fix the missing alt and title tag for all images. Automate where possible.
  • The project takes 1 week to complete.