WordPress multisite disable all default widgets on site creation

I’m unable to find how to disable the default widgets on site creation. By this I mean when I create a site within a WordPress multisite network, it does not create the sidebar widgets such as “meta” automatically.

I see plugins that haven’t been updated in two plus years that may help me with this, but I don’t want to download anything that old.

Read More

Does anyone know how to do this?

Related posts

2 comments

  1. The default widgets are created by a call to update_option() in wp_install_defaults() in wp-admin/includes/upgrade.php.

    After wp_install_defaults() has been called by wpmu_create_blog() in wp-includes/ms-functions.php, the action wpmu_new_blog is fired.

    You can, therefore, hook into wpmu_new_blog and remove the default widgets by calling update_option() again, this time with an empty array for sidebar-1.

    add_action('wpmu_new_blog', function($blog_id){
        switch_to_blog($blog_id);
        update_option('sidebars_widgets',
            ['wp_inactive_widgets' => [], 'sidebar-1' => [], 'sidebar-2' => [],
             'sidebar-3' => [], 'array_version' => 3]);
        restore_current_blog();
    });
    

Comments are closed.