1

I like to use a child-theme.

The parent functions.php

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

2

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' );
}
  • I just edit the quotes // Remove all widgets from Starkers-Theme add_action( 'after_setup_theme', 'remove_default_sidebars', 11 ); function remove_default_sidebars(){ remove_action( 'widgets_init', 'starkers_widgets_init' ); } – ogni Apr 22 '12 at 17:22
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

  • A note for future readers that will not understand why @leogopal answered referring to widgets: in the meanwhile I fixed the title and tags of the original question that previously was "Unregister widget from Child-Theme". Apparently from ogni question (and according to the accepted answer) he/her was referring to sidebars not single widgets, despite the previously given title. legopal answer is still a good answer (more descriptive than the approved one, BTW): give it a look if you are trying to remove a sidebar but you just need to remove a widget :) – furins Jun 2 '15 at 9:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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