I am thinking about random theme from 2-3 selected themes, which is shown for new user and saved to cookies or ip, to not show other theme for him again. Just show random themes for new users, so I could see witch theme is better performing.

Is it possible to do this kind of a plugin or create a function for a wordpress? I found that plugin http://wordpress.org/extend/plugins/wordpress-ab-theme-split-tests/ but it seems not to be working properly and I need much simpler solution with possibility to choose few themes to spin from. Please help guys.

  • The plugin you have referenced allows you to create different templates within the same Theme. The Theme is an integral part of Wordpress and not somthing that can be changed 'on the fly', specificlly because the ABSPATH constant references the Theme directory. Thus it is your site that has a Theme assigned to it, not the visitor.
    – David Gard
    Jan 20, 2015 at 16:40
  • Let's assume you can serve random themes without problems, what are you going to measure and how? Why not test one theme for some time, before trying another one?
    – birgire
    Jan 20, 2015 at 16:42

1 Answer 1


I'll preface this by saying I don't think it's the best of ideas, but in the interest of answering the question...

The general idea is to filter template, option_template, and option_stylesheet in a plugin and return your desired template slug. The rest of the code is just setting and reading the cookie.

 * Plugin Name: WPD Theme Switcher

class WPD_Theme_Switcher {

    private $themes = array(
    private $current_theme = '';
    private $cookie = 'wpd_theme_switcher_cookie';

    function __construct() {

        if( empty( $this->current_theme ) && !isset( $_COOKIE[ $this->cookie ] ) ) {
            $this->current_theme = $this->themes[ array_rand( $this->themes ) ];
            setcookie( $this->cookie, $this->current_theme, time() + (10 * 365 * 24 * 60 * 60) );
        } else {
            $this->current_theme = $_COOKIE[ $this->cookie ];

        // don't switch themes for admin requests
        if( ! is_admin() ){
            add_filter( 'template', array( $this, 'theme_switcher' ) );
            add_filter( 'option_template', array( $this, 'theme_switcher' ) );
            add_filter( 'option_stylesheet', array( $this, 'theme_switcher' ) );


    function theme_switcher(){
        return $this->current_theme;

new WPD_Theme_Switcher();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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