Archived topic
Facebook pixel queries
7 replies · Started by Helen on March 17, 2017
Hi there,
I've placed my base Facebook pixel code in the wp_head section in GP Hooks. Does the execute PHP box need to be ticked?
I expect that the above will post the pixel code to every page, but is there also a way to post a different pixel code to a specific page, for example a custom event pixel for sign-up page?
Many thanks for your help,
Helen
ps - Happy St Patrick's Day from Ireland!
Hi Helen,
Can you share the code you used on here?
Thanks.
Happy St Patrick's Day! :)
If you need it to show up on specific pages, you would need to use PHP.
For example:
<?php if ( is_page( 'my-page-slug' ) ) { ?>
Your FB pixel code for yourwebsite.com/my-page-slug
<?php } ?>
Many thanks for your replies. The code I've placed in wp_head is below, it was copied from Facebook's pixel helper and is for my basic 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', '123mypixelcode'); // Insert your pixel ID here.
fbq('track', 'PageView');
</script>
If I want to add a specific pixel to a single page I would add Tom's code underneath and tick the execute pho box, is that correct?
So my code in wp_head is now:
<!-- 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', '123mypixelcode'); // Insert your pixel ID here.
fbq('track', 'PageView');
</script>
<?php if ( is_page( 'my-page-slug' ) ) { ?>
Your FB pixel code for yourwebsite.com/my-page-slug
<?php } ?>
Is that correct?
Many thanks indeed for your help,
Kind regards,
Helen
Hi Helen,
You would first want to replace the "Your FB pixel code for yourwebsite.com/my-page-slug" from Tom with the actual facebook code (from <script> to </script>).
Then replace "my-page-slug" with the actual page slug that you want to apply the facebook setting.
Let us know if this is clear.
It might be easier to use a plugin: https://en-ca.wordpress.org/plugins/oh-add-script-header-footer/
This way you can just add your FB code onto the pages you want it to appear :)
Thanks Leo and Tom,
That's very clear and helpful. I'll try both ways and post here again if I can't get one of them going.
Cheers,
Helen
Glad we could help!