Tagged: 

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #637018

    I want to add the Facebook Conversion Pixel to the header of a single page on my site. I know how to add the Google Analytics code to my site, but that adds the code to every page. The Facebook Conversion Pixel has to be added to the header of only the conversion page. How do I do that? And I really would prefer not to do it with a plugin.

    I’m seeing other comments about adding script to the functions.php file. Can this be done for just a single page with the page ID? Can you give me exactly what code should be added to the functions.php file and where to change the page ID? Thanks

    • This topic was modified 8 years, 6 months ago by TheURLdr.
    #637091

    Hey Kim!

    Add the following to your header page

    <?php if is_page('page_id'); { ?>
    the code here 
    <?php } ?>

    let us know if that helps you out

    Best regards,
    Basilis

    #637093

    Thanks Basilis, but I have no idea what that does. It’s obviously only a piece of what needs to be done, but I have no idea what to do from here. Can you please explain exactly what that does and what else I need to do?

    #637124

    Hi,

    Thanks for getting back to us!

    In the code example Basilis gave you need to add your Facebook Conversion Pixel code and the ID number of the conversion page.

    So when adding the code to the header file change the following that is in bold:

    <?php if is_page(‘page_id‘); { ?>
    the code here
    <?php } ?>
    If you still need assistance let us know.

    Best regards,
    Jordan

    #639527

    Jordan,
    Thanks for clarifying the code, but I’m still confused where to put this. The only place I know to put the code is in the functions.php within the child theme. Basisilis is saying to add it to “your header page.” How would I do that?

    Update – I tried adding this to the functions.php file and it broke the page in question.

    • This reply was modified 8 years, 5 months ago by TheURLdr.
    #640137

    Hi,

    You can find the header.php file in the Appearance > Editor panel. However, in order to preserve this modification, you have to duplicate the header.php file in a child theme if you have one and add the modification so instead of doing that, edit the functions.php file then insert this code:

    function ava_fb_px_conversion(){
        if ( is_page( PAGE ID HERE )) {
    	?>
    	FACEBOOK PIXEL COVERSION CODE HERE
    	<?php
        }
    }
    add_action('wp_head', 'ava_fb_px_conversion');

    If you can give us the FACEBOOK PIXEL CONVERSION snippet, we’ll complete the code for you.

    Best regards,
    Ismael

    #640139

    Hi,

    You can try this in your functions.php file, if that doesn’t work then please post the exact code you want to add:

    function enfold_add_facebook_pixel(){
    if is_page('page_id'); { 
    ?>
    the code here 
    <?php } ?>
    }
    add_action('wp_head', 'enfold_add_facebook_pixel');

    Regards,
    Rikard

    #890475

    Hi
    How can I use the function for a portfolio post?
    I have tried
    function enfold_add_facebook_pixel(){
    if is_single($post = ‘5412’); {
    but is breaking the website
    Thank you

    Solved Thank You Anyway
    function ava_fb_px_conversion(){
    if ( is_single( 5412 )) {
    ?>
    <!– Facebook Pixel Code –>

    • This reply was modified 6 years, 11 months ago by manurimini.
    #890694

    Hi,

    Great, glad you got it working. I’ll close this thread for now.

    Best regards,
    Rikard

Viewing 9 posts - 1 through 9 (of 9 total)
  • The topic ‘Adding tracking code to the header on a single page’ is closed to new replies.