I don't know how to explain this question but let me try, Just Imagine I've a website called xyz.com and in xyz there are 10 themes uploaded and in homepage i'll show name & screenshot of all 10 themes if someone click on activate / demo then that theme will be activated in his ip address only till his session destroy after it when he visit again after sometime he can see old theme.

Means if someone wanted to buy theme from my site he can able to view it directly from my site.


Drop this inside a .php file in in wp-content/mu-plugins:

add_filter('template',   'check_for_theme_preview');
add_filter('stylesheet', 'check_for_theme_preview');

// if you want to display the theme selector
// (this is wrong, you need a custom action in each of your themes, after <body>)
add_action('wp_head',    'display_template_selector');

// checks for the "theme-preview" argument, and changes the template
function check_for_theme_preview($template){

    $template = $_SESSION['template'];

  // sanitize this!     
    $template = $_GET['theme-preview'];

  $_SESSION['template'] = $template;

  return $template;

// theme selector
function display_template_selector(){

  $themes = get_themes(); ?>

  <select onchange="document.location.href = this.options[this.selectedIndex].value;">
    <?php foreach($themes as $theme_name => $theme_data): ?>
    <option value="<?php echo add_query_arg('theme-preview', $theme_data['Template']) ?>"><?php echo $theme_name; ?></option>
    <?php endforeach; ?>


So pointing your browser to http://yoursite.com/?theme-preview=twentyten will make the site load that template, for the entire session.

But there are plugins out there that do this better...

  • That plugin is really cool but if theme doesn't support widget area then user can't switch theme again. – Mohit Bumb Oct 15 '11 at 13:29
  • I assume you have no control over the themes if you're asking that. In that case insert the display function in wp_footer and move it to the top of the page with javascript. – onetrickpony Oct 15 '11 at 13:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.