How to (definitively) add Facebook tracking pixel to child theme

Hello,
I"m needing help with how to put in the tracking pixel in my header on the child theme. It isnt working. I’ve scoured the forum and I can’t find something simple and definitive. Here’s the code I have in the xpro child theme:

// Add scripts to wp_head()
function child_theme_head_script() { ?>

(My pixel code is in here)

<?php } add_action( 'x_before_site_begin', 'child_theme_head_script' ); Please help. Thank you. Stephen

Hello Stephen,

Thanks for asking. :slight_smile:

Adding Facebook pixel code in child theme will require changes in theme files. I suggest you to please download, install and setup child theme from following resource.

https://theme.co/apex/child-themes

After that please add following code in child theme function.php file:

// Begin Facebook Pixel Code
function my_facebook_pixel_code(){
?>

<!-- Replace this line with Pixel Code provided by Facebook -->

<?php 
}
add_action( 'wp_head', 'my_facebook_pixel_code' );
// End Facebook Pixel Code

You also have the option to use plugin inrder to get job done. You can use Header and Footer plugin to add Facebook Pixel code.

Here is a tutorial that you can use to get started with Header and Footer plugin.

Thanks.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.