Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #707093

    I am trying to add the Facebook pixel to my WordPress website with Enfold and an Enfold child-theme installed.

    In my functions.php I have added the following code (removed ids for privacy concerns):

    function facebook_pixel(){ ?>
    <!-- Facebook Pixel Code -->
    <script>
    !function(f,b,e,v,n,t,s){if(f.fbq)return;n=f.fbq=function(){n.callMethod?
    n.callMethod.apply(n,arguments):n.queue.push(arguments)};if(!f._fbq)f._fbq=n;
    n.push=n;n.loaded=!0;n.version='2.0';n.queue=[];t=b.createElement(e);t.async=!0;
    t.src=v;s=b.getElementsByTagName(e)[0];s.parentNode.insertBefore(t,s)}(window,
    document,'script','https://connect.facebook.net/en_US/fbevents.js');
    fbq('init', '487168541485291');
    fbq('track', 'PageView');
    </script>
    <noscript><img height="1" width="1" style="display:none"
    src="https://www.facebook.com/tr?id=**************&ev=PageView&noscript=1"
    /></noscript>
    <!-- DO NOT MODIFY -->
    <!-- End Facebook Pixel Code -->
    <?php
    }
    add_action('wp_head', 'facebook_pixel');

    This code above should show in the <head> section of all my pages, but it doesn’t.

    function facebook_completeregistration(){
            if ( is_page( 291 )) {
    	?>
    	fbq('track', 'CompleteRegistration');
    	<?php
            }
    }
    add_action('wp_head', 'facebook_completeregistration');

    This code above should show in the <head> section of page with id 291, but it doesn’t.

    What am I missing here?

    #707099

    I fixed it. It was a caching problem :(
    But also the second code needed <script> tags in order to work.

    function facebook_completeregistration(){
            if ( is_page( 291 )) {
    	?>
    	<!-- Facebook Pixel Code CompleteRegistration -->
    	<script>
    	fbq('track', 'CompleteRegistration');
    	</script>
    	<!-- End Facebook Pixel Code CompleteRegistration -->
    	<?php
            }
    }
    add_action('wp_head', 'facebook_completeregistration');

    Maybe this is still useful for other Enfold-users who want to track conversions by adding code to functions.php :)

    #707114

    Hi!

    Glad you figured it out and thank you for sharing your solution :)
    Let us know if you have any other questions or issues!

    Best regards,
    Yigit

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.