Shortcode with WordPress Google Website Optimizer Plugin

First of all, props to Chris who first suggested the fix to the WordPress Google Website Optimizer Plugin in the

Tweet This

Written by Damon on February 1, 2009

First of all, props to Chris who first suggested the fix to the WordPress Google Website Optimizer Plugin in the comments on my WordPress Displaying Code in Square Brackets post. Chris shares his ideas on how to make money online at The Net Hustle.

If you’re having trouble getting the Google Website Optimizer plugin to work with shortcode (code in square brackets that you insert into your posts add plugin functionality), then you need to change the echo statements to return statements in the google-website-optimizer-for-wordpress.php file.

I added some other modifications to the script to make it easier to read. I only just started testing it, but I’m pretty confident the code below will work without modification.

Copy the code and replace the function of the same name in google-website-optimizer-for-wordpress.php (everything between the two lines that start with add_action, but not including the add_action lines).


function go4wp_tracking_script($content) {
global $wp_query;
if (is_single() or is_page()) {
if ($wp_query->post) {
$post = $wp_query->post;
$tracking = get_post_meta($post->ID, 'go_tracking_script_test', true);
$conversion = get_post_meta($post->ID, 'go_tracking_script_conversion', true); //this line got edited after original post
//if the page/post has both test and conversion code, display both
if (get_post_meta($post->ID, 'go_tracking_script_test', true) && get_post_meta($post->ID, 'go_tracking_script_conversion', true)) {
return $content.$tracking.$conversion;
//if the page/post has test code display it
} else if (get_post_meta($post->ID, 'go_tracking_script_test', true)) {
return $content.$tracking;
//if the page/post has conversion code, display it
} else if (get_post_meta($post->ID, 'go_tracking_script_conversion', true)) {
return $content.$conversion;
//if the page/post does not have test and/or conversion code, display the normal content
} else {
return $content;
}
}
} else {
return $content;
}
}


1 reply to “Shortcode with WordPress Google Website Optimizer Plugin

Leave a Reply

Your email address will not be published. Required fields are marked *