Last active
February 14, 2018 19:10
-
-
Save douglaskarr/fd715da1db15f65195e3f6fb40759e42 to your computer and use it in GitHub Desktop.
WordPress: Add A/B Testing Functionality to Gravity Forms
This file contains 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 | |
// Add to your functions.php theme file | |
// Modified slightly from Mediacause so all you need to do is add _ab to your shortcode and then specify your forms | |
// Credit: https://mediacause.org/ab-testing-forms-using-gravity-forms/ | |
function shortcode_gravityforms_ab($atts){ | |
$a = shortcode_atts( array( | |
'id' => '', | |
'title' => 'false', | |
'description' => 'false', | |
'ajax' => 'false' | |
), $atts); | |
$ids = explode(",", $a['id']); | |
$count = count($ids) - 1; | |
if($count > 0){ | |
$rand = mt_rand(0,$count); | |
return do_shortcode('[gravityform id="'. $ids[$rand].'" title="'. $a['title']. '" description="'. $a['description'] .'" ajax="'. $a['ajax'] .'"]'); | |
} | |
} | |
add_shortcode('gravityform_ab', 'shortcode_gravityforms_ab'); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment