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.


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.

   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.


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'

remove_theme_support('widgets') won't work because of:

function remove_theme_support( $feature ) {
// Blacklist: for internal registrations not used directly by themes.
if ( in_array( $feature, array( 'editor-style', 'widgets', 'menus' ) ) )
    return false;

return _remove_theme_support( $feature );

The "Widgets" menu item is added by wp_widgets_add_menu(), called in the _admin_menu hook, as set up by wp_maybe_load_widgets(). You can disable this by unhooking it from _admin_menu or returning false for load_default_widgets.

You can also unregister all sidebars as Bainternet suggested, and remove_theme_support( 'widgets' ).

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.