Completely disabling widgets

How do I completely remove widget support from a theme/plugin ?

Like removing the appearance -> widgets page, and prevent WP from loading widget classes and all widget-related stuff.

Related posts

Leave a Reply

4 comments

  1. One option would be to simply flush the widget code out of the sidebar.php file, as well as the header/footer/post pages if they are using widgets.

    However, take a peek at this code snippet (courtesy of this site), which you can add to your functions.php file and will disable the widgets. I think this would be a cleaner approach if you’re looking to change themes and sill have widgets disabled.

    <?php 
       add_filter( ‘sidebars_widgets’, ‘disable_all_widgets’ ); 
       function disable_all_widgets( $sidebars_widgets ) 
       { 
          if ( is_home() ) $sidebars_widgets = array( false ); 
          return $sidebars_widgets; 
       } 
    ?>
    

    Note that this will only disable the widgets on your home page, so you’ll need to find the additional conditionals for individual pages/posts/etc.

  2. If you make use of the internal functions from widgets.php, then it’s as easy as this:

        // final function makes most sense
        // (useing stuff like `$GLOBALS['wp_widget_factory']` will do nothing better than this ex.)
       // place inside your functions.php  
    
        unregister_widget( 'some widget' );
    
        // if my search results are right, these should be the available default widgets 
        // from /wp-includes/widgets.php
        Line 389:   'wp_widget_pages',
        Line 390:   'wp_widget_pages_control',
        Line 391:   'wp_widget_calendar',
        Line 392:   'wp_widget_calendar_control',
        Line 393:   'wp_widget_archives',
        Line 394:   'wp_widget_archives_control',
        Line 395:   'wp_widget_links',
        Line 396:   'wp_widget_meta',
        Line 397:   'wp_widget_meta_control',
        Line 398:   'wp_widget_search',
        Line 399:   'wp_widget_recent_entries',
        Line 400:   'wp_widget_recent_entries_control',
        Line 401:   'wp_widget_tag_cloud',
        Line 402:   'wp_widget_tag_cloud_control',
        Line 403:   'wp_widget_categories',
        Line 404:   'wp_widget_categories_control',
        Line 405:   'wp_widget_text',
        Line 406:   'wp_widget_text_control',
        Line 407:   'wp_widget_rss',
        Line 408:   'wp_widget_rss_control',
        Line 409:   'wp_widget_recent_comments',
        Line 410:   'wp_widget_recent_comments_control'