简体   繁体   中英

WordPress footer widgets are not displaying in my child theme

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?

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM