Skip to content

Instantly share code, notes, and snippets.

@joshua-chavanne
Last active March 2, 2017 20:26
Show Gist options
  • Save joshua-chavanne/503d550daf68674e9b1faae07f7f89d2 to your computer and use it in GitHub Desktop.
Save joshua-chavanne/503d550daf68674e9b1faae07f7f89d2 to your computer and use it in GitHub Desktop.
UTM Variable A/B Test Content Shortcode
<?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');
@joshua-chavanne
Copy link
Author

Need to rewrite to allow a "default" as well in case of missing GET variable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment