skip to Main Content

I’m building an ecommerce store with Woocommerce for WordPress using the Storefront theme. I created a child theme to remove the default sidebar, however this also has the side effect that widgets in the footer widget areas are not displayed. If I switch back to the parent theme, they work just fine.

This is the functions.php of the child theme:

<?php
function mb_remove_sidebar() {
    return false;
}

add_filter( 'is_active_sidebar', 'mb_remove_sidebar', 10, 2 );

How can I get the footer widgets back?

2

Answers


  1. Your code is removing all sidebars. Note the sidebar ID you want to remove and then unregister the specific sidebar.

    add_action( 'widgets_init', function() {
        unregister_sidebar( 'your-sidebar-id' );
    }, 11 );
    

    For more information see https://codex.wordpress.org/Function_Reference/unregister_sidebar

    Login or Signup to reply.
  2. The best way to do this in my opinion would be to create your own sidebar.php file in your child them to overwrite the parent and edit the code here instead of within your functions.

    Below is the default file, you can simply remove the exclamation mark in the if statement.

    <?php
    /**
     * The sidebar containing the main widget area.
     *
     * @package storefront
     */
    if ( ! is_active_sidebar( 'sidebar-1' ) ) {
        return;
    }
    ?>
    
    <div id="secondary" class="widget-area" role="complementary">
        <?php dynamic_sidebar( 'sidebar-1' ); ?>
    </div><!-- #secondary -->
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search