fix code - ?> <script> !function(f,b,e,v,n,t,s){…
- User
fix code - ?> !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', '196861943395577'); fbq('track', 'PageView'); <?php
add_action('wp_head');
- Assistant
To fix the code, remove the opening <?php tag because it is unnecessary and causing a syntax error. Also, the add_action() function should have a callback function specified, like 'wp_head' in this case. Here's the corrected code:
html<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', '196861943395577'); fbq('track', 'PageView'); </script> <noscript><img height="1" width="1" style="display:none" src="https://www.facebook.com/tr?id=196861943395577&ev=PageView&noscript=1" /></noscript>Note: Make sure to place this code in an appropriate location within your HTML or PHP file.
- User
add this code to wp_head - !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’, ‘196861943395577’); fbq(‘track’, ‘PageView’); <img height=“1” width=“1” style=“display:none” src=“https://www.facebook.com/tr?id=196861943395577&ev=PageView&noscript=1” />
- Assistant
To add the code to the
wp_headaction in WordPress, you can use thewp_headhook with thewp_headfunction. Here's how you can modify the code to add it to thewp_headaction:php<?php function add_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', '196861943395577'); fbq('track', 'PageView'); </script> <noscript><img height="1" width="1" style="display:none" src="https://www.facebook.com/tr?id=196861943395577&ev=PageView&noscript=1" /></noscript> <?php } add_action('wp_head', 'add_facebook_pixel_code'); - User
add this code to wp_head -
- Assistant
To add the provided code to the
wp_headaction in WordPress, you can modify the previous solution. Here's the updated code:php<?php function add_facebook_pixel_code() { ?> <!-- Meta 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', '196861943395577'); fbq('track', 'PageView'); </script> <noscript><img height="1" width="1" style="display:none" src="https://www.facebook.com/tr?id=196861943395577&ev=PageView&noscript=1" /></noscript> <!-- End Meta Pixel Code --> <?php } add_action('wp_head', 'add_facebook_pixel_code');