Tagged: x
-
AuthorPosts
-
June 2, 2016 at 12:33 pm #1022612
Hi,
I’ve been trying to learn how to add my Facebook Pixel to a specific page on my site through other forum posts. To the best of my knowledge I did it correctly but it still isn’t working.
To explain what I did..
I’ve set up a child theme but I have one question, in WordPress when you go to Appearance>Themes do I activate X or X Child Theme?
Next I tried to find the functions.php file (through FTP) from
/themes/x/framework/views/ethos
(I’m running the ethos view) but there was no functions.php folder therefore I created one. I then added the Facebook Pixel to the file. It looks like this:// Add scripts to wp_head() function head_scripts() { ?> is_page( 496 ) { <!-- 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','//connect.facebook.net/en_US/fbevents.js'); fbq('init', '1529188017408925'); fbq('track', "PageView"); fbq('track', 'CompleteRegistration'); </script> <noscript><img height="1" width="1" style="display:none" src="https://www.facebook.com/tr?id=1529188017408925&ev=PageView&noscript=1" /></noscript> <!-- End Facebook Pixel Code --> } <?php }
Lastly I copied the whole
/ethos
folder containing the newfunctions.php
file from x to the/themes/x-child/framework/views
folder replacing the/ethos
folder that was previously there.Any mistakes?
Thanks,
PascalJune 2, 2016 at 3:16 pm #1022903Hey There,
Codes added to functions.php are applied sitewide. The easiest way to insert code into a single page would be to use the page editor for that particular page. You can easily add your code in there using “Raw content” element in cornerstone.
Hope that helps.
June 3, 2016 at 11:46 am #1024469Thanks!
June 3, 2016 at 9:24 pm #1025126Hi There,
Are you sure your page ID is 496? Please update your code to this:
add_action( 'x_before_site_begin', 'facebook_pixel_code' ); function facebook_pixel_code(){ if(is_page(496) ) : ?> <!-- 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','//connect.facebook.net/en_US/fbevents.js'); fbq('init', '1529188017408925'); fbq('track', "PageView"); fbq('track', 'CompleteRegistration'); </script> <noscript><img height="1" width="1" style="display:none" src="https://www.facebook.com/tr?id=1529188017408925&ev=PageView&noscript=1" /></noscript> <!-- End Facebook Pixel Code --> <?php endif; }
Because of this condition
if(is_page(496)
this code will only output on the page with the ID of 496.You need to place this on your child theme’s functions.php file. Look for that file on this directory /wp-content/themes/x-child/.
Yes, you need to activate the child theme.
Hope it helps, Cheers!
-
AuthorPosts