Activate a Default Theme on New Network Sites
Switches every newly created site to the theme you choose instead of the latest default theme.
Opens WPIDE on
Code
if ( ! is_multisite() ) {
return;
}
$wpide_theme = 'twentytwentyfour'; // Theme folder (stylesheet) name.
add_action( 'wp_initialize_site', function ( $site ) use ( $wpide_theme ) {
$theme = wp_get_theme( $wpide_theme );
if ( ! $theme->exists() ) {
return;
}
switch_to_blog( $site->blog_id );
switch_theme( $theme->get_stylesheet() );
restore_current_blog();
}, 200 );
Notes
Use the theme's folder name; the theme must be installed. Network-enable it too if site owners should be able to switch back to it.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.