Skip to content

Instantly share code, notes, and snippets.

@sjaved87
Last active July 12, 2016 06:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sjaved87/75ee7167a162475fa7b3 to your computer and use it in GitHub Desktop.
Save sjaved87/75ee7167a162475fa7b3 to your computer and use it in GitHub Desktop.
This mu-plugin will switch theme on all subsites (except main site) at once. Just change the theme directory slug, save chagnes and move it to wp-content/mu-plugins folder (create if not exists). Be care full if you have hundreds of sites then its not the right approach (will take some time and needs some resources) but good for handsome sites, …
<?php
function wpmu_change_theme_on_all_subsites(){
global $switched;
$theme_directory_slug = 'twentyfourteen';
$sites = wp_get_sites( $args );
if($sites){
foreach ($sites as $key => $value) {
if( is_main_site($value['blog_id']) ) continue;
switch_to_blog( $value['blog_id'] );
switch_theme( $theme_directory_slug );
restore_current_blog();
}
}
}
add_action('init', 'wpmu_change_theme_on_all_subsites');
@megmorsie
Copy link

I'm curious about how you'd accomplish this if there were 100s of sites...
Would you just use get_blog_count to see if it's over a certain amount then divide it into smaller chunks with a counter that stopped the loop at, say 50, then log the site where it left off to pick up at again? Or is there a better method?

Edit: I now see there are params for "limit" and "offset" for wp_get_sites, which would make more sense to use.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment