WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have two themes: "Default" and "Alternate".

I'd like to place a link on my site that says "Switch to Alternate Theme", which will change the default theme to the alternate and vice versa. A cookie would be set to save which theme the user is currently on, so when they return they will see the last theme they selected.

How do I change the theme on the fly in wordpress?


share|improve this question
There are a lot of plugins with related functionality or are you interested in how to implement this from scratch? – Rarst Nov 8 '10 at 9:08
I'm using a user agent theme switcher plugin that works great, but I want to include a link that will allow the user to have control of which theme is displayed for them. I wasn't able to find a simple plugin that has this functionality. I might have missed one though. Is there a specific one that you know of that have this functionality? I'm up for writing one from scratch, I'm just unsure what I need to call to switch a theme. – jaysonp Nov 8 '10 at 9:18

You can use Theme Switch and Preview.

If you are up for coding this yourself, you can use the template and stylesheet filters.

E.g.: to switch to Twenty Ten:

function custom_load_twenty_ten_template() {
    return 'twentyten';

function custom_load_twenty_ten_stylesheet() {
    return 'twentyten';

add_filter( 'template', 'custom_load_twenty_ten_template' );
add_filter( 'stylesheet', 'custom_load_twenty_ten_stylesheet' );
share|improve this answer
thank you , its working for me , but how i can make this work for a theme listed in a plugin directory /plugins/mobview/theme/ ?! i tried to use " register_theme_directory " then get the mobile theme out of it , but didn't work !!! – Hamza Dec 27 '10 at 12:24
The location of the theme does not matter. If the theme is called Mobview e.g., you will use 'mobview' instead of 'twentyten'. – sorich87 Dec 27 '10 at 19:41

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.