Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

share|improve this question

1 Answer 1

up vote 2 down vote accepted

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"]
share|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
    
awesome man. thanks so much for all your help. –  Steve Fischer Apr 20 '11 at 14:20

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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