Last active
March 2, 2017 20:26
-
-
Save joshua-chavanne/503d550daf68674e9b1faae07f7f89d2 to your computer and use it in GitHub Desktop.
UTM Variable A/B Test Content Shortcode
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 | |
function ab_tester_shortcode_callback($atts, $content = null){ | |
$display = false; | |
$a = shortcode_atts(array( | |
'variant_key' => 'utm_variant', | |
'variant' => 'default', | |
'method' => 'GET' | |
),$atts); | |
if($a['method']=='GET'){ | |
if( ( $_GET[$a['variant_key']]==$a['variant'] ) || | |
( $a['variant']=='default' && ( empty( $_GET[$a['variant_key']] ) ) ) | |
) | |
{ | |
$display = true; | |
} | |
} | |
if($display==true){ | |
echo $content; | |
} | |
} | |
add_shortcode('ab_tester_content','ab_tester_shortcode_callback'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Need to rewrite to allow a "default" as well in case of missing GET variable.