Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question
    
maybe removing the sidebars codex.wordpress.org/Function_Reference/unregister_sidebar –  Bainternet Mar 24 '11 at 14:30

4 Answers 4

up vote 3 down vote accepted

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.

share|improve this answer

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' ).

share|improve this answer
    
does remove_theme_support( 'widgets' ) have any effect? I tried it and widgets still show up if you have sidebars defined –  onetrickpony Mar 24 '11 at 15:08
    
@One Trick Pony: I think it is relatively new, but it is certainly used in the Admin Bar when adding links to the widget page. –  Jan Fabry Mar 24 '11 at 15:19

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'
share|improve this answer

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

http://wpseek.com/remove_theme_support/

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 );
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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