Last active
October 26, 2024 21:58
-
-
Save pH-7/454a6dfefac5c32bf4d5 to your computer and use it in GitHub Desktop.
Split Testing (marketing A/B testing) with Wordpress - Display a Random Page with Wordpress. Frensh Tutorial π https://01script.com/page-aleatoire-wordpress-split-testing/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Front to the WordPress application. This file doesn't do anything, but loads | |
* wp-blog-header.php which does and tells WordPress to load the theme. | |
* | |
* @package WordPress | |
*/ | |
/** | |
* Tells WordPress to load the WordPress theme and output it. | |
* | |
* @var bool | |
*/ | |
define('WP_USE_THEMES', true); | |
$aDaysList = ['Tue', 'Wed', 'Fry', 'Sun']; // EX: On Tuesday, Wednesday, Friday and Sunday, redirect to "squeeze-page2", otherwise leave it on the usual squeeze page | |
$sOriginalSalesPage = 'squeeze-page1'; // Edit it to your Original Sale Page, the Wordpress Page Name | |
$sAlternativeSalesPage = 'squeeze-page2'; // Edit it to your Alternative Sale Page, the Wordpress Page Name | |
set_split_test($sOriginalSalesPage, $sAlternativeSalesPage, $aDaysList); // Run the A/B testing | |
/** Loads the WordPress Environment and Template */ | |
require(dirname(__file__) . '/wp-blog-header.php'); | |
/** | |
* @author Pierre-Henry Soria <[email protected]> | |
* @copyright (c) 2015-2020, Pierre-Henry Soria. All Rights Reserved. | |
* @link http://github.com/pH-7/ | |
* @link https://01script.com/page-aleatoire-wordpress-split-testing/ | |
* | |
* Set a Wordpress A/B Testing Page | |
* | |
* @param string $sOriginalSalesPage Original Sale Page; the Wordpress Page Name Only (without slash). | |
* @param string $sAlternativeSalesPage Alternative Sale Page; the Wordpress Page Name Only (without slash). | |
* @param array $aDaysList Weekdays when the alternative sale page is displayed. Three first letters (with uppercase) | |
* e.g., array('Tue') = Display the alternative page on Tuesday. | |
* | |
* @return void | |
*/ | |
function set_split_test($sOriginalSalesPage, $sAlternativeSalesPage, $aDaysList) | |
{ | |
$sDay = date('D'); | |
$sPath = str_replace('/', '', $_SERVER['REQUEST_URI']); | |
$sHttp = (!empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS'] == 'on')) ? | |
'https://' : 'http://'; // Check SSL compatibility | |
if (in_array($sDay, $aDaysList, true) && $sPath === $sOriginalSalesPage) { | |
header('HTTP/1.1 301 Moved Permanently'); | |
header('Location: ' . $sHttp . $_SERVER['HTTP_HOST'] . '/' . $sAlternativeSalesPage); | |
exit; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment