Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

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){
  session_start();

  if(isset($_SESSION['template']))
    $template = $_SESSION['template'];

  // sanitize this!     
  if(isset($_GET['theme-preview']))
    $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; ?>
  </select>
  <?php

}

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...

share|improve this answer
    
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

 
discard

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

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