• I am attempting to make a cleaned version of WordPress that I can use for client websites, and therefore I want to be able to remove all of the default widgets and simply add in the ones I want to use by commenting out a line in the function.

    I have tried using the following code:

    add_action('widgets_init', 'remove_default_widgets', 10);
    function remove_default_widgets()
    {
    unregister_sidebar_widget('pages');
    }

    And also

    function unregister_problem_widgets() {
    unregister_sidebar_widget('Calendar');
    unregister_sidebar_widget('Search');
    }
    add_action('widgets_init','unregister_problem_widgets');

    Unfortunately neither of them have worked. Is there anything additional I have to put in my template file, or any calls I have to put anywhere else. Or has the way this is handled changed?

Viewing 3 replies - 1 through 3 (of 3 total)
  • WP 2.8 changed some things with widgets. Try this:

    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' );
    }

    There’s a couple of more widgets, but I not sure of their names offhand. Just look them up in /wp-includes/default-widgets.php.

    Thread Starter Darfuria

    (@darfuria)

    You genius, thank you very much ??

    The other defaults are:

    unregister_widget( 'WP_Widget_Meta' );
    unregister_widget( 'WP_Widget_Recent_Comments' );
    unregister_widget( 'WP_Widget_RSS' );
    unregister_widget( 'WP_Widget_Text' );

    Note that this gets rid of the widget entirely. See unregister_sidebar_widget for a version that disables specific instances of a widget.

    But what if you want to get more specific still and disable widgets on a template-by-template basis, rather than globally? I did–wanted to disable (all instances of) the Recent Posts widget, but only in the home.php template (where it would be redundant).

    To do that, I had to get my hands dirty and wrote this code at the top of my template file:

    foreach ($wp_registered_widgets as $widget) {
      if ($widget['name'] == 'Recent Posts') {
        unset($wp_registered_widgets[$widget['id']]);
      }
    }
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Unregister Widgets’ is closed to new replies.