Tagged: child theme, facebook, functions.php, javascript, pixel
Viewing 3 posts - 1 through 3 (of 3 total)
-
AuthorPosts
-
November 2, 2016 at 2:10 pm #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?
November 2, 2016 at 2:25 pm #707099I 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 :)
November 2, 2016 at 2:41 pm #707114 -
AuthorPosts
Viewing 3 posts - 1 through 3 (of 3 total)
- You must be logged in to reply to this topic.