\r\n\r\n\r\n","answerCount":1,"datePublished":"2018-01-13T17:34:50+00:00","author":{"@type":"Person","name":"jonB-5","url":"https://toolset.com/forums/users/jonb-5/"},"acceptedAnswer":{"@type":"Answer","text":"You can\\'t add HTML to the Layouts JS panel, and the snippet provided uses HTML to provide a fallback for non-JavaScript users. If you disregard non-JavaScript users, you can add only the JavaScript portion of this code to Layouts JS:\\n<code>\\n!function(f,b,e,v,n,t,s)\\n {if(f.fbq)return;n=f.fbq=function(){n.callMethod?\\n n.callMethod.apply(n,arguments):n.queue.push(arguments)};\\n if(!f._fbq)f._fbq=n;n.push=n;n.loaded=!0;n.version=\\'2.0\\';\\n n.queue=[];t=b.createElement(e);t.async=!0;\\n t.src=v;s=b.getElementsByTagName(e)[0];\\n s.parentNode.insertBefore(t,s)}(window, document,\\'script\\',\\n \\'https://connect.facebook.net/en_US/fbevents.js\\');\\n fbq(\\'init\\', \\'1643227992405344\\');\\n fbq(\\'track\\', \\'PageView\\');\\n</code>\\n\\nTo use the HTML fallback, you must enqueue this script some other way. Some themes provide places where you can insert custom code like this from wp-admin. Some do not, and you must enqueue the code manually instead. See below.","datePublished":"2018-01-20T15:49:31+00:00","upvoteCount":1,"url":"https://toolset.com/forums/topic/unable-to-get-facebook-pixel-js-to-work-in-layouts-js-editor/","author":{"@type":"Organization","name":"Toolset","url":"https://toolset.com"}}}}}
Skip NavigationProblem: I want to insert the following code in Layouts JS to include a Facebook Pixel tracker:
<!-- 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', '1643227992405344'); fbq('track', 'PageView'); </script> <noscript><img height="1" width="1" style="display:none" src="https://www.facebook.com/tr?id=1643227992405344&ev=PageView&noscript=1" /></noscript> <!-- End Facebook Pixel Code -->
Solution: You can't add HTML to the Layouts JS panel, and the snippet provided uses HTML to provide a fallback for non-JavaScript users. If you disregard non-JavaScript users, you can add only the JavaScript portion of this code to Layouts JS:
!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', '1643227992405344'); fbq('track', 'PageView');
To use the HTML fallback, you must enqueue this script some other way. Some themes provide places where you can insert custom code like this from wp-admin. Some do not, and you must enqueue the code manually instead. See below.
Relevant Documentation: http://www.wpbeginner.com/wp-tutorials/how-to-install-facebook-remarketingretargeting-pixel-in-wordpress/
This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.
Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.
Our next available supporter will start replying to tickets in about 1.29 hours from now. Thank you for your understanding.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | - | - |
13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | - | - |
Supporter timezone: America/New_York (GMT-04:00)
This topic contains 2 replies, has 2 voices.
Last updated by 6 years, 10 months ago.
Assisted by: Christian Cox.