Disable default WordPress widgets in sidebar

This function will disable all widgets:

add_filter( 'sidebars_widgets', 'wpse134172_disable_all_widgets' );

function wpse134172_disable_all_widgets( $sidebars_widgets ) {
   if (true == true) {
     $sidebars_widgets = array( false );
     }
   return $sidebars_widgets;
   }

Now the true=true conditional will disable them all the time, while you only want this to happen with a clean install. So you will have to add a different conditional. Which one depends on your actual purpose.

You could use is_active_widget to test whether only the standard widgets are active.

Another option would be to use the after_switch_theme hook to make the deactivation only happen when your theme is activated.

You could even detect whether the user has visited the widgets page in the backend and decide that after this he apparently is cool with the widgets as they are. This would involve setting an option in the database.

Leave a Comment