What is the best practice for adding google conversion tracking code to a specific page?


User needs it in his footer so I think you should use conditional page logic. Something like:

If ( is_single(postID)) { //insert tracking code  }

You can also use the post title or post slug, but id is the most reliable.

Old Answer

I would consider writing a shortcode. Add the following to your functions.php file. You can specify input parameters. In this case I specify id and target.

add_shortcode( 'signup', 'signup_shortcode' );

function signup_shortcode( $atts ) {
extract( shortcode_atts( array(
    'id' => '',
    'target' => '',
), $atts ) );

$HTML = 'hello world'.$id;

return $HTML;


Then call it in your post like so:

[signup id="1234" target="goog"]
| improve this answer | |
  • thats a pretty cool idea. I was way off. the code only needs to be on one page. so i guess i need to add conditional statement to call the function?!? – Steve Fischer Apr 18 '11 at 20:56
  • You don't need conditional logic to call it. You will call it in the actual text of your post and it will be included inline as the page is rendered. If you needed the code to be in the head or the footer of the page then this is not the solution for you. I updated my code as I left $foo in there when it should have been $id. Try sticking the code block in your functions.php and calling the [signup] in a post and I think how it works will be immediately obvious. – mrtsherman Apr 18 '11 at 22:11
  • yeah. i need the code in the footer thats why i mentioned conditional logic – Steve Fischer Apr 19 '11 at 13:00
  • I guess so then. I'll update my answer with an if statement that may work for you. – mrtsherman Apr 19 '11 at 19:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.