Want to switch between two themes according to a specific criteria ?
Edit : Try this plugin if your criteria is based on an URI pattern
Just add and activate this small plugin by creating a file wp_theme_switcher.php in Wordpress plugins directory with the following content:
<?php /* Plugin Name: WP Theme Switcher Description: Automatically switch Wordpress themes on the fly Version: 2.0 Author: Fayçal Tirich Author URI: http://agafix.org Plugin URI: http://agafix.org/how-to-automatically-switch-wordpress-themes-onthefly/ */ class WP_Theme_Switcher { public $current_theme; public $theme_to_apply; public $current_page; public function __construct() { $this->current_page = 'http://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']; $current_theme_data = get_theme(get_current_theme()); $this->current_theme = $current_theme_data["Template"]; $this->theme_to_apply = $this->current_theme ; } public function get_theme_to_apply(){ $default_theme = "default"; $alternatif_theme = "classic"; //your criteria if ($_GET['cat']==3){ $this->theme_to_apply = $alternatif_theme; } return $this->theme_to_apply ; } public function switch_theme_when_it_has_to_be(){ add_filter( 'template', array(&$this, 'get_theme_to_apply') ); add_filter( 'stylesheet', array(&$this, 'get_theme_to_apply') ); } } $wp_theme_switcher = new WP_Theme_Switcher(); add_action('setup_theme', array(&$wp_theme_switcher,'switch_theme_when_it_has_to_be')); ?>
For example imagine you have two themes : my_ar_theme for Arabic content and my_jp_theme for Japanese one and you want Wordpress to be able to switch between them on the base of the blog URI (eg : if the URI contains a “/ar/” substring like for www.example.org/ar/post or a “/jp/” like for www.example.org/jp/post)
In this case the code to past will be
<?php /* Plugin Name: WP Theme Switcher Description: Automatically switch Wordpress themes on the fly Version: 2.0 Author: Fayçal Tirich Author URI: http://agafix.org Plugin URI: http://agafix.org/how-to-automatically-switch-wordpress-themes-onthefly/ */ class WP_Theme_Switcher { public $current_theme; public $theme_to_apply; public $current_page; public function __construct() { $this->current_page = 'http://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']; $current_theme_data = get_theme(get_current_theme()); $this->current_theme = $current_theme_data["Template"]; $this->theme_to_apply = $this->current_theme ; } public function get_theme_to_apply(){ $default_theme = "default"; $alternatif_theme = "classic"; //your criteria $pattern="/ar/"; if (!empty($pattern)){ // Credits to Yann Dubois if( preg_match("/" . preg_replace( '|/|', '/', $pattern ) . "/i", $this->current_page ) ) { $this->theme_to_apply = $alternatif_theme; } } return $this->theme_to_apply ; } public function switch_theme_when_it_has_to_be(){ add_filter( 'template', array(&$this, 'get_theme_to_apply') ); add_filter( 'stylesheet', array(&$this, 'get_theme_to_apply') ); } } $wp_theme_switcher = new WP_Theme_Switcher(); add_action('setup_theme', array(&$wp_theme_switcher,'switch_theme_when_it_has_to_be')); ?>
Another example is to switch the theme only some days a week as asked Brooke in comments
<?php /* Plugin Name: WP Theme Switcher Description: Automatically switch Wordpress themes on the fly Version: 2.0 Author: Fayçal Tirich Author URI: http://agafix.org Plugin URI: http://agafix.org/how-to-automatically-switch-wordpress-themes-onthefly/ */ class WP_Theme_Switcher { public $current_theme; public $theme_to_apply; public $current_page; public function __construct() { $this->current_page = 'http://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']; $current_theme_data = get_theme(get_current_theme()); $this->current_theme = $current_theme_data["Template"]; $this->theme_to_apply = $this->current_theme ; } public function get_theme_to_apply(){ $default_theme = "default"; $alternatif_theme = "classic"; $alternatif_theme_days = array('Monday','Friday','Sunday'); //your criteria if (in_array(date('l'), $alternatif_theme_days)) { $this->theme_to_apply = $alternatif_theme; } return $this->theme_to_apply ; } public function switch_theme_when_it_has_to_be(){ add_filter( 'template', array(&$this, 'get_theme_to_apply') ); add_filter( 'stylesheet', array(&$this, 'get_theme_to_apply') ); } } $wp_theme_switcher = new WP_Theme_Switcher(); add_action('setup_theme', array(&$wp_theme_switcher,'switch_theme_when_it_has_to_be')); ?>
You can download this last example via this link
The same goes for more than two themes, just define your concerned themes, change your criteria, activate the plugin and watch the Wordpress magic flexibility !

























December 29th, 2009
at 11:44
Is it possible to transform this hack to a plugin?
December 29th, 2009
at 11:54
yep
and in this case you just have to install the plugin only one time (no more need to copy past the code as many as your themes number
but you know, I also have to develop an easy way to let users specifying their own criteria (according to a substring in URI like in this example or may be it can be the current category or the current author etc etc etc…)
Inchallah when I will have time
December 31st, 2009
at 19:04
this could also be used to switch at a certain time of day or day of the week? stuff like that?
December 31st, 2009
at 20:44
Yes of course
this is an example http://agafix.org/how-to-automatically-switch-wordpress-themes-onthefly/#brooke
The script is also a plugin now, so just create the file in plugin directory, customize it and activate it
January 9th, 2010
at 20:09
Hey Dos, I made a plugin to make your life easy
throw a glance at http://wordpress.org/extend/plugins/wp-theme-switcher/screenshots/
January 9th, 2010
at 22:23
Your a life saver dude
January 9th, 2010
at 22:40
aw yesss, youre the best
January 26th, 2010
at 21:41
If I wanted to change my theme based on the time of day would that be possible? If so what code do I need to change for the plugin to work?
January 27th, 2010
at 09:55
It can be something like http://codepad.org/TxBUf8Ni
January 27th, 2010
at 16:35
Could this be modified to change themes on a specific date? So on 01/01 it would display a New Year’s Day theme?
Fantastic work on it so far, btw.
January 27th, 2010
at 20:08
try this plugin http://wordpress.org/extend/plugins/dayswitcher/
January 27th, 2010
at 20:35
Close, but not quite what I need. DaySwitcher sets a theme for an entire month at a time.
February 1st, 2010
at 11:20
Hi thanks for this plugin. Is it possible to show a different theme depending from which site the user is coming?
Thank you very much
February 5th, 2010
at 15:57
this is a start http://codepad.org/INDs3gew
February 20th, 2010
at 13:13
not working.
is this working for wp 2.9.1?
March 24th, 2010
at 09:30
I get a fatal error when I try to activate the plugin
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or ‘}’ in (removed exact location)/wp-theme-switcher.php on line 13
April 21st, 2010
at 20:35
i’d like to use ur plugin, and i ask if you know the best and stabl plugin for translation (RTL and LTR)?
Ur Angel
thanks
April 23rd, 2010
at 09:52
Hi, this is a great plugin, but there is still a bug in the new version 2.0 of the plugin. I tried to contact you but no answer. You have to modify the pattern preg on line 37 of the ‘get_theme_to_apply()’ to accept slashes. Please contact me by email so I can send you the fix. It’s very simple. It is important to fix this: we like your plugin a lot, but do not want to fix it manually each time you upgrade ;-)
Thanks
April 23rd, 2010
at 10:21
@Martin : Are you using PHP4 or PHP5 ?
@Kamal : It depends on your needs… but they say that http://wpml.org is the best
@Yann: Thanks for the fix ! And how can I contact you in my turn ?
April 23rd, 2010
at 12:44
@Fayçal: I sent you the proposed fix by e-mail. Thanks again.
April 23rd, 2010
at 15:46
After installation (WP 292) when I modifed the settings:
Warning: preg_match() [function.preg-match]: Unknown modifier ‘/’ in /data03/virt23880/domeenid/www.meediamaa.ee/htdocs/test/wp-content/plugins/wp-theme-switcher/wp-theme-switcher.php on line 37
Warning: preg_match() [function.preg-match]: Unknown modifier ‘/’ in /data03/virt23880/domeenid/www.meediamaa.ee/htdocs/test/wp-content/plugins/wp-theme-switcher/wp-theme-switcher.php on line 37
Warning: preg_match() [function.preg-match]: Unknown modifier ‘/’ in /data03/virt23880/domeenid/www.meediamaa.ee/htdocs/test/wp-content/plugins/wp-theme-switcher/wp-theme-switcher.php on line 37
Warning: preg_match() [function.preg-match]: Unknown modifier ‘/’ in /data03/virt23880/domeenid/www.meediamaa.ee/htdocs/test/wp-content/plugins/wp-theme-switcher/wp-theme-switcher.php on line 37
Warning: preg_match() [function.preg-match]: Unknown modifier ‘/’ in /data03/virt23880/domeenid/www.meediamaa.ee/htdocs/test/wp-content/plugins/wp-theme-switcher/wp-theme-switcher.php on line 37
April 23rd, 2010
at 15:49
@Toomas:
Yes this is exactly the bug I have signaled to Fayçal. This is due to the use of a “slash” character in the pattern expression.
I have sent Fayçal a bugfix, so he should be able to quickly fix it. Otherwise, I can post a quick fix here.
April 23rd, 2010
at 16:00
A commit to wordpress repository is planned for this night, thanks for reporting and resolving the problem
April 23rd, 2010
at 20:06
Thanks guys for the fix
April 24th, 2010
at 09:46
Hi!
Thank you wery much. It works. This is the only plugin what works with Artisteer generated themes. I have tested 10 different plugins.
May 11th, 2010
at 10:29
Many, many thanks for this.
May 13th, 2010
at 13:15
This plugin is very handy! One question. Can I make it work with subdomains? E.g. http://en.mysite.com goes to one theme and http://fr.mysite.com goes to another?
Thanks!
May 13th, 2010
at 13:49
Yes of course, you have two choices :
1- use this optimized code http://codepad.org/Wacs6B05 (save this file in your plugin directory)
2- install http://wordpress.org/extend/plugins/wp-theme-switcher/ and set your URI pattern from the plugin options page ( http://en.yoursite.com/* -> your_en_theme and http://fr.yoursite.com/* -> your_fr_theme )
May 14th, 2010
at 03:49
Thanks so much for the reply! Worked like a CHARM!
June 23rd, 2010
at 15:41
You’re a genius. Exactly what I’m looking for. Thanks