0

I need to add new sidebars for using them accordingly on different pages throughout my shop.

I use Woocommerce and my own Storefront child theme.

This is a snippet of what is in functions.php file of the child theme.

add_action( 'init', 'init_storefront_child' );

function init_storefront_child() {

    // It seems Wordpress doesn't take into consideration the 2 lines below.
    remove_action( 'widgets_init', 'storefront_widgets_init' ); // Not fired (or overrided by something)
    add_action( 'widgets_init', 'storefront_child_widgets_init' ); // Not fired (or overrided by something)
}

function storefront_child_widgets_init() {

    register_sidebar( array(
        'name'          => __( 'Blog Sidebar' ),
        'id'            => 'blog',
        'description'   => 'Sidebar displaying in blog.',
        'before_widget' => '<aside id="%1$s" class="widget %2$s">',
        'after_widget'  => '</aside>',
        'before_title'  => '<h3 class="widget-title">',
        'after_title'   => '</h3>',
    ) );
}

So the sidebars in 'Appearance > Widgets' menu don't change and stay the same as originally.

I tried to change the code directly in storefront theme files and it works but that's not at all the solution.

What's happen with the 'widgets_init' hook in functions.php's child theme?

Thanks by advance.

1
  • Just add priority to your remove and add actions above the default 10 Sep 24, 2015 at 13:52

2 Answers 2

0

In your child theme's 'functions.php' file, you need to use the remove_action( 'widgets_init', '$name' ); script. For instance, in your twentytwelve-child theme's functions.php file, use:

remove_action( 'widgets_init', 'twentytwelve_widgets_init' ); //necessary to replace parent theme's code

and then hook your new widget in your child theme's function

add_action( 'widgets_init', 'new_twentytwelve_widgets_init', 0 );
0

I just needed to change the priority on init_storefront_child to 0 so it fires after all the functions have been hooked but before the hooks actually execute:

add_action( 'init', 'init_storefront_child', 0 );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.