Search code examples
phpwordpressab-testing

A/B Split Test For Wordpress


We manage our websites with Wordpress. Recently, we started searching for split test plugins and tools but couldn't find something that supports the following requirements:

  1. Test the same post with changes in the Single Post (single.php) file
  2. Test changes in stylesheet (stylesheet.css)
  3. Test changes in themes

I would appreciate any assistant if anyone is aware of existing tools that can help.


Solution

  • We didn't find any solution online so we built one. In order to make it work, I duplicated the active theme, made the changes in the duplicated theme and created a plugin that dynamically load the themes randomly - 50% the original theme and 50% the duplicated.

    The plugin code is as follow:

    <?php
    /*
    Plugin Name: Theme Split Test
    Plugin URI: 
    Description: Theme Split Test
    Author: Tal Yaari
    Author URI: 
    Version: 1.0
    */
    
    add_filter('template', 'load_theme');
    add_filter('option_template', 'load_theme');
    add_filter('option_stylesheet', 'load_theme');
    function load_theme($theme) {
    
        $rand = intval(date('s'));
        if ($rand%2 == 0)
        {
            $theme = 'devoe';
        }
        else
        {
            $theme = 'devoe1';
        }
    
        return $theme;
    }
    ?>