Pages

Monday, November 19, 2012

Automatically assign a different theme randomly for every new site in Wordpress Multisite

If you are the Multisite Super Admin of your Wordpress installation, then you must have felt the need to automatically assign a different theme for every new site that gets registered.

Currently what is happening in Wordpress Multi Sites is the same default theme that you initially assign will be used by all sites - and to me that's quite boring, especially when the admins of those sites do not change the default sites. It can also be an equally boring experience if you have disabled the Themes option for your sites and thus every user gets same theme.

Here is a simple trick from your wordpress kid:

  •  Step 1: Open wp-config.php file 
    • I'm sure you would know how to open this file. For those who don't please go to control panel of your hosting service provider where you can find the wordpress installation files. You wil find wp-config.php right in the root directory of your site.
  • Step 2: Just before the line which says "*/ That's all, stop editing! Happy blogging. */" paste this following code:
    • $theme1 =  'surface'; //theme1 folder name
       $theme2 = 'colorway'; //theme2 folder name
       $theme3 = 'amdhas'; //theme3 folder name
       $theme4 = 'swedish-grays'; //theme4 folder name
      
       $array = array($theme1, $theme2, $theme3, $theme4);
       $random_theme = $array[rand(0, count($array) - 1)];
      
       define('WP_DEFAULT_THEME', $random_theme);
  • Note that your theme folder names should be included in the variables $theme1, $theme2 etc. They are not theme names, but they are the folder names containing your themes. You can get these folder names in the wp-content/themes folder
  • Step 3: Sit back, take rest because you're done
    • The above code does the trick of assigning a random theme for every new user. 
If you face any difficulties, you could simple comment here and I will try to respond. That's two cents from Wordpress Kid. Thanks for reading. 

No comments:

Post a Comment