Unregister sidebar from Child-Theme

I like to use a child-theme.

The parent functions.php

Read More
function starkers_widgets_init() {
// Area 1, located at the top of the sidebar.
register_sidebar( array(
    'name' => __( 'Primary Widget Area', 'starkers' ),
    'id' => 'primary-widget-area',
    'description' => __( 'The primary widget area', 'starkers' ),
    'before_widget' => '<li>',
    'after_widget' => '</li>',
    'before_title' => '<h3>',
    'after_title' => '</h3>',
) );

// Area 2 ...

My child-theme functions.php

function xtreme_unregister_sidebar() {
    unregister_sidebar('primary-widget-area');
    }
    add_action( 'childtheme_sidebars', 'xtreme_unregister_sidebar' );

But doesn´t work for.
Thanks

Related posts

Leave a Reply

2 comments

  1. Check the code bellow, I think that should work.

    add_action( 'after_setup_theme', 'remove_default_sidebars', 11 );
    function remove_default_sidebars(){
        remove_action( 'widgets_init', 'starkers_widgets_init' );
    }
    
  2. The Title of this post is for unregistering widgets not really sidebars, though I am glad the user got what they were looking for. For those searching for how to unregister widgets using a child-theme where the widget was registered in the parent theme, you can do that with this:

    Assuming the Parent Theme’s Widget is registered at the widgets_init hook, all you need to do is wrap your unregister_widget() call inside of a function, hook that function into widgets_init, and give your hook a higher priority number than the Parent Theme’s widgets_init-hooked function.

    Assuming the Parent Theme hooks into widgets_init without giving a priority number, the function will default to 10. So, just give your hook call a priority of 11 or greater.

    so something like this:

    add_action( 'widgets_init', 'remove_theme_widgets', 11 );
    
    function remove_theme_widgets() {
        unregister_widget('parent_theme_widget_class');
    }
    

    Source