switch themes with a filter

switch themes with a filter

A while back someone asked on twitter if there were an easy way to change all sites in a network to a different one. Yes, that's fairly easy to do with a simple plugin that you put in the mu-plugins* folder.

[code]function ra_switch_to_twentyten() {
global $wpdb;

$last_id = get_site_option( 'ra_twentyten', 1 );
if( $last_id < 0 )

$next_id = $wpdb->get_var( $wpdb->prepare( "SELECT blog_id FROM $wpdb->blogs WHERE blog_id > %d LIMIT 1", $last_id ) );
if( !$next_id ) {
update_site_option( 'ra_twentyten', -1 );
switch_to_blog( $next_id );
if( 'default' == get_option( 'template' ) ) {
update_option( 'template', 'twentyten' );
update_option( 'stylesheet', 'twentyten' );
update_option( 'current_theme', '' );

update_site_option( 'ra_twentyten', $next_id );
add_action( 'init', 'ra_switch_to_twentyten' );[/code]

You need to leave this in the mu-plugins folder long enough for the plugin to cycle through all the blogs in the network. Then the code can be removed. In the above case, every site would eventually be switched to Twenty Ten.

* See What is the mu-plugins folder if you are unfamiliar.

(Visited 6 times, 1 visits today)
  • Dan
    Posted at 12:30h, 06 October Reply

    Awesome. This will save me a ton of time and work 🙂

Post A Comment