1
votes

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
The sidebar contains the widgets. So it's logical that the widgets are not displayed if you remove the sidebar!jrswgtr
There are several widget areas. The sidebar is one, but there are also widget areas in the footer. Removing the sidebar shouldn't remove the widgets from the footer.ReddaJoppe
Alas if that is the case, and they are disappearing it is logical to think that the footer widgets or the call to them is in the sidebar. I might suggest you look in the sidebar for any additional functions/actions relating to footer widgets, and move said functions/actions to your included footer.php code.Aliqua
@JeppeBech the point is that every "widget area" is called a sidebar. Your code removes all of them. So if you only want to remove the specific sidebar you will have to get the ID of that sidebar and only remove that one.jrswgtr

2 Answers

1
votes

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

0
votes

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 -->