Last active
July 12, 2016 06:22
-
-
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, …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.