Removing Default Widgets in WordPress

Building my first WP theme and I quickly realized that I need to remove all the default widgets since I will be building my own.

So my question is what function do I need in my function.php file for this to happen =)

Read More

Thanks!

Related posts

Leave a Reply

2 comments

  1. I think this is the code you’re looking for:

    add_action( 'widgets_init', 'my_unregister_widgets' );
    
    function my_unregister_widgets() {
        unregister_widget( 'WP_Widget_Pages' );
        unregister_widget( 'WP_Widget_Calendar' );
        unregister_widget( 'WP_Widget_Archives' );
        unregister_widget( 'WP_Widget_Links' );
        unregister_widget( 'WP_Widget_Categories' );
        unregister_widget( 'WP_Widget_Recent_Posts' );
        unregister_widget( 'WP_Widget_Search' );
        unregister_widget( 'WP_Widget_Tag_Cloud' );
    }
    
  2. This is a much better solution.

    remove_action( 'init', 'wp_widgets_init', 1 );
    add_action( 'init', function() {  do_action( 'widgets_init' ); }, 1 );
    

    This is future proof and better than letting WordPress register them then unregistering them. This solution prevents the default widgets from even being registered.