Deregistering Parent Theme Widgets in WordPress

I had a “fun” time figuring out how to deregister parent theme widgets in WordPress the other day so I went through the codex and learned a lot about how functions are called in function.php. I learned about something I didn’t know – you can specify the order of priority that something has within a hook!

This made deregistering widget areas pretty easy. In twentyten (something I child theme from a fair bit), the widgets are added on line 373 with code that looks like this:

function twentyten_widgets_init() {   
  // Area 1, located at the top of the sidebar.                                                                    
    register_sidebar( array(                                                                                         
    'name' => __( 'Primary Widget Area', 'twentyten' ),                                                          
    'id' => 'primary-widget-area',
   // and so on
 

So, you write an unregister function in your child theme’s functions.php that looks something like this:

function my_unregister_sidebars() {                                                                                  
    unregister_sidebar('primary-widget-area');                                                                       
    unregister_sidebar('secondary-widget-area');                                                                     
    unregister_sidebar('first-footer-widget-area');                                                                  
    unregister_sidebar('second-footer-widget-area');                                                                 
    unregister_sidebar('third-footer-widget-area');                                                                  
    unregister_sidebar('fourth-footer-widget-area');                                                                 
} 

Then you just call that in the widgets init hook, but give it a later priority:

  add_action( 'widgets_init', 'my_unregister_sidebars', 11);                                                           
  add_action( 'widgets_init', 'my_widgets_init',12);

Google wasn’t super helpful for me until after I had figured out the solution to the problem. So, if you need to unregister widgets in a child theme, this is how to do it.

(Feel free to tell me if I have typoed anywhere.)

4 thoughts on “Deregistering Parent Theme Widgets in WordPress

  1. 0
    Paul

    BRILLIANT!!!! … I’d tried this last week but it didn’t work out.

    Thanks again for this little gem!!! :-)

    (cool bg image on your site by the way!!)

  2. 0
    Paul

    … Just to clarify my last comment!!!… The reference to my attempt not working was proir to reading this post!!!!

    ….. THIS WORKS!!! ….

    I’ve used it on 4 sites already, makes for a much cleaner Admin area for my clients!…

    Thanks again!!

    :-p

  3. 0

Comments are closed.