Om Google Conversion doelen bij te houden moet je soms op bepaalde pagina’s een zogenaamde Google Conversion code plaatsen. Binnen WordPress installatie kan het toevoegen van dergelijke codes soms lastig zijn. Daarom heb ik een eenvoudig WordPress shortcode gemaakt waarmee je eenvoudig een Google Conversion code kunt toevoegen aan je WordPress pagina’s.
/** * Google Conversion Code */ function prefix_shortcode_google_conversion_code($atts) { extract(shortcode_atts(array( 'id' => null , 'language' => 'en' , 'format' => 3 , 'color' => '666666' , 'label' => '' , 'value' => 0 , ), $atts)); $crlf = "\r\n"; $noScriptImageUrl = sprintf('http://www.googleadservices.com/pagead/conversion/%d/', $id); $noScriptImageUrl = add_query_arg(array( 'label' => $label , 'guid' => 'ON' , 'script' => 0 ), $noScriptImageUrl); $output = ''; $output .= '<!-- Google Code for Bezoekers Pagina Douchegoten Remarketing List -->' . $crlf; $output .= '<script type="text/javascript">' . $crlf; $output .= '/* <![CDATA[ */' . $crlf; $output .= sprintf('var google_conversion_id = %d;', $id) . $crlf; $output .= sprintf('var google_conversion_language = "%s";', $language) . $crlf; $output .= sprintf('var google_conversion_format = "%s";', $format) . $crlf; $output .= sprintf('var google_conversion_color = "%s";', $color) . $crlf; $output .= sprintf('var google_conversion_label = "%s";', $label) . $crlf; $output .= sprintf('var google_conversion_value = %d;', $value) . $crlf; $output .= '/* ]]> */' . $crlf; $output .= '</script>' . $crlf; $output .= '<script type="text/javascript" src="http://www.googleadservices.com/pagead/conversion.js">' . $crlf; $output .= '</script>' . $crlf; $output .= '<noscript>' . $crlf; $output .= '<div style="display:inline;">' . $crlf; $output .= sprintf('<img height="1" width="1" style="border-style:none;" alt="" src="%s"/>', esc_attr($noScriptImageUrl)) . $crlf; $output .= '</div>' . $crlf; $output .= '</noscript>' . $crlf; return $output; } add_shortcode('google_conversion_code', 'prefix_shortcode_google_conversion_code');
Deze shortcode is met name interessant zijn in combinatie met WordPress webwinkel plugins zoals WooCommerce of Jigoshop. Om de shortcode ook op de product categorieën te kunnen gebruiken zullen de shortcodes ook toegepast moeten worden op de product categorieën beschrijvingen.
/** * Add shortcode support to term description */ function prefix_term_description($description) { if(is_archive()) { $description = do_shortcode($description); } return $description; } add_filter('term_description', 'prefix_term_description');
Één reactie op “WordPress Google Conversion shortcode”
[…] 2012 schreef ik in het bericht “WordPress Google Conversion shortcode” al over hoe je eenvoudig een Google Conversion shortcode kunt integereren in een WordPress […]