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;
}
}
Original Source:http://www.damongudaitis.com/wordpress/shortcode-google-website-optimizer-plugin.html
Related Stuff
Google Buzz Button Wordpress Plugin ReleasedIf you are looking for a Google Buzz button to add into your Wordpress site then we have released the first Wordpress plugin exclusively ...
Plug And Play Ecommerce With Wordpress PluginsSince 2003 Wordpress has slowly been gaining popularity amongst the elite of the internet, the bloggers. It is one of those few things ...
Add Google Search to Your WordPress BlogThe native WordPress search does not return very relevant results, thus it makes a lot of sense to add Google Search into your WordPress ...
Add More Sidebars to Your WordPress ThemeYou can add more than one sidebar section to your WordPress site. For example, with the stc-intermountain.org site, I added a whole bunch ...
Series Posting in WordpressIn my functions.php file, I have some code which implements series posting. This relies on the thematic ...
