UPDATED 2008-10-31
Style switchers in web sites can serve various purposes:
- Accessibility
- Flexibility in general
- User choice
- Fun
I wanted to add one to op111.net for all of the above reasons. After looking at various solutions for WordPress, I decided to use a theme switcher instead. This one:
wordpress.org/extend/plugins/theme-switcher-reloaded
You can try it here at op111.net (below the RSS links), to see if you like the way it works. If you do, keep reading! :-)
In Internet Explorer 6 you’ll only see different colours, not widths. To be fixed. Sorry!
Theme Switcher Reloaded in action: I just switched to the wide style of op111.net. The string with the theme name in it will be removed on the next page change. It is appended for XHTML and CSS validation.
CONTENTS
- Why this solution, Compatibility notes
- Making an alternative theme/style
- Setting up Theme Switcher Reloaded: 2 methods
- Notes
- Links
1. Why this solution, Compatibility notes
Normally, theme switchers are used in theme directories or by theme designers, to showcase themes. So, why do I use one as a style switcher? Because I found that overall, compared to the alternatives I looked at, I liked Theme Switcher Reloaded better:
1.1. Why Theme Switcher Reloaded
- It is easy to set up.
- It works well.
- It works fast.
- It works from any page without redirecting to the home page.
- It allows to check styles/themes for valid XHTML and CSS.
- It comes with a widget. (Alternatively, text or image links can be used.)
- It offers possibilities not available in a style switcher.
Acknowledgements
I want to thank Josh Wood of Utopian.net and Themebot of Themebot for answering my questions about the performance of Style Switcher Reloaded. This could be a concern in some cases, e.g. traffic surges, or sites on budget hosting, but the switcher does not seem to be heavy on the server.
1.2. Compatibility of Theme Switcher Reloaded
Theme Switcher Reloaded 1.0:
- Works well with WordPress 2.6 and 2.7. [INFO UPDATED 2008-10-31]
- Does NOT work well with WP Super Cache. To explain. Both plugins work exactly as they should, which is where the problem lies: Theme Switcher Reloaded switches the theme, but WP Super Cache keeps serving cached content, so the change only becomes visible after the next cache refresh.
2. Making an alternative theme/style
Style switchers switch stylesheets. Here, however, since a theme switcher is used, you will have to make alternative themes.
This is very easy. Thanks to WordPress “child themes”, making alternative themes is essentially the same as making alternative stylesheets: In its elementary form, a child theme is just one directory with just one stylesheet in it. See this introduction and how-to:
How to make a child theme for WordPress
An advantage of using child themes for the alternative styles is that you only have to add rules for the difference, which makes for small, clean files, easy to manage. For example, the dark style of op111.net is essentially one stylesheet with only chromatic rules in it, to override the colours of the default theme and define a dark background and light text in their place.
So, for instance, while the default theme/style has this rule for the HTML body:
body {
background-color: #fff;
color: #111;
font-family: candara, "liberation sans", verdana,
"lucida grande", helvetica, sans-serif;
font-size: 87.50%;
margin: 1.0em auto 0.5em;
max-width: 66.0em;
padding: 0 1.0em;
}
… in the dark style the rule for the body is just two declarations:
body {
background-color: #272727;
color: #dfdfdf;
}
3. Setting up Theme Switcher Reloaded: 2 methods
Unless you are a good designer, the difficult part in all this is making good alternative styles. Setting up Theme Switcher Reloaded is just clicks and copy/paste.
First, download and install the plugin:
wordpress.org/extend/plugins/theme-switcher-reloaded
… and then pick one of two ways to display the style options…
3.a. Included widget
Go to Design, Widgets, and add the “Theme Switcher” widget to the sidebar. You can customize its title, if you want, and also choose between a list and a drop-down menu for the style options.
The second option of the second pair (“short name (faster loading)”) does not support child themes, but, in any case, this is useful for large collections of themes. (With 5 or 10 themes installed I did not feel any difference.)
The one problem of the widget in this particular implementation is that you cannot select themes to display; each and every theme you have installed is made available to your visitors to switch to:
Oops!
The quick ’n’ dirty solution is to delete every theme but the ones you want to display. If I did this, I would keep a couple of themes in an auxiliary directory nearby, to be able to do a quick cut/paste in case of emergency.
3.b. Text or image links
The alternative method is to use text or image links. In this method you select just the styles you want. The links will have this form:
<a href="?wptheme=Theme Name" title="Blah blah">Blah</a>
The URI of the href attribute is the most important part, and the name of the theme must be entered exactly as it is, case-sensitively.
To return to the example of Arietta and Arietta/dark, make two links:
<a href="?wptheme=Arietta" title="Default style">Default</a> | <a href="?wptheme=Arietta/dark" title="Dark style">Dark</a>
… then go to Design, Widgets, add a “Text” widget to the sidebar, paste the links and click Save Changes:
For more styles, more links can be added:
… which appears like this:
4. Notes
4.1. Cookie duration
Style Switcher Reloaded stores the style preference of each visitor in a cookie, which has a life of 1000 hours, that is, 42 days. This is more than enough for a themes directory but maybe too short for other sites. To change the cookie duration, find this line in theme-changer-reloaded.php:
$expire = time() + 3600*1000; // cookie set to expire in 1 hour
Don’t let the comment —“cookie set to expire in 1 hour”— confuse you. It is obviously a left-over. (Since the time() function works with seconds, not milliseconds.)
… and change the value. For 1 year, use 60*60*24*365 or 31536000:
$expire = time() + 31536000; // Cookie set to expire in 1 year.
4.2. Suggestions, Ideas, Questions
Have any ideas, suggestions, questions, corrections, or objections? You are most welcome to leave a comment!
Thanks for reading and happy style-switching!
5. Links
THEME SWITCHER RELOADED
Home: themebot.com/webmaster-tools/wordpress/wordpress-plugins
wordpress.org: wordpress.org/extend/plugins/theme-switcher-reloaded
OTHER
- www.smashingmagazine.com/2008/06/05/style-switchers-are-back-ideas-examples-and-a-contest
- “Style Switchers Are Back: Ideas, Examples and a Contest”. Lots of ideas and examples for possible implementations of style switchers. — Results of the contest: www.smashingmagazine.com/2008/06/25/style-switchers-contest-results
Changelog
- 2008-10-31
- Added compatibility note for TSR and WP 2.7 (works!).
- Removed child themes example (unnecessary repetition of op111.net/p53).






10 Comments
Hi, thanks for the article. My problem is a little different and I’m not sure if it is possible. I am working on a site right now and I want the online store to have a different theme than the rest of the site. Is there a way to do this? When the user clicks the store button I would like it to take them to the store page AND also change the theme to the different theme I have set up for the shop. Any help is appreciated, thanks!
Hi, Alex!
If the changes can be made with CSS alone, you can use Headspace2 to link an external stylesheet or insert an internal stylesheet for the shop page only.
I you need to load a complete theme with templates etc., Headspace2 can do this too — at least it has the option. I just tried in my test installation (runs WP 2.7), and it didn’t work.
Headspace2: http://urbangiraffe.com/plugins/headspace2/
Great post - thanks!
Thanks, Peter! Glad you liked it!
Hi Demetris.
I like a lot the functionality of your plugin, but it has been impossible for me to make it work correctly.
I created the child themes and when i change them in the wordpress admin interface, they are working perfectly, so i conclude that the child themes are ok, but when i try to change them dinamicly using you plugin, i can’t do it.
I have a parent theme which is the source of my templates and my base css. and then i established some child themes to modify the color schemes. The parent theme’s name is “fundaperdis” and i established “template: fundaperdis” and the css “../fundaperdis/style.css”in all of the children themes. As i told you, in wordpress admin interface they are working 100%. I change theme and the theme is changing, but when i try to change them with the plugin calling the wptheme variable and passing the name of the theme as the value, i could’nt get it right. Please help me
@Nestor Rojas
Hey, Nestor! Do you, by any chance, have any caching plugin installed? What you describe is what I saw when I tried the theme switcher with the WP Super Cache plugin installed.
Other than that, I have no idea. You can send the theme and the child theme, if you want:
http://op111.net/contact
so that I can check to see if they work here, on op111.net.
btw, the plugin is not mine. :-) I just wrote the how-to.
On the links given by you, I still find the older version which was last updated on 23 April 2008. Where can I get the latest version from?
@Navjot Singh — You mean for Theme Switcher Reloaded? Both links have the latest version, 1.0, dated 22 February 2008.
Then what’s this supposed to be?
2008-10-31
Added compatibility note for TSR and WP 2.7 (works!).
Removed child themes example (unnecessary repetition of op111.net/p53).
Ah! You’re right. That can be confusing. This is when *I* updated the *information*, to add that Theme Switcher Reloaded is also compatible with the new version of WordPress, 2.7.
I’ll rephrase the note, to make it clearer.
2 Trackbacks
[...] to themebot.com to check for any instructions. I don’t see anything there, but thankfully Demetris posted a link for a “how-to.” He is using this plugin to act as a style switcher, [...]
[...] to themebot.com to check for any instructions. I don’t see anything there, but thankfully Demetris posted a link for a “how-to.” He is using this plugin to act as a style switcher, [...]