Support » Fixing WordPress » Error adding FB Pixel to functions.php

  • Resolved jlcule


    I am trying to add the Facebook Pixel code to the functions.php of my child theme. I don’t know anything about PHP, so I followed the instructions of this page

    The problem is that the pixel does not work: it does not load (I am using the Facebook Pixel Helper extension for Chrome). I don’t know anything about PHP, so I think I did not implement the code well. The functions.php of my child theme has a code for Google Analytics too, so I don’t know if it’s a problem too. I made a screenshot of the content of my functions.php file:

    I know I can add both tracking codes to the header.php of my child theme, but the Admin Control Panel of WordPress does not give me access and, as I am using a child theme, I prefer add the code to functions.php.


    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz


    The FB code is appearing correctly on your site’s home page, so you’ve done everything correctly as far as PHP is concerned. External code like this can conflict with other code and is nearly impossible to debug because the external code is all minified.

    One thing to try is hooking “wp_footer” instead of “wp_head”. This causes the script output to appear closer to the closing </body> tag, which sometimes is thought to help. If you add your hook with a large priority number, there’s a good chance your code will be the last script listed on the page.

    Another thing to try is to remove the FB script portion and remove the <noscript> tags so only the web pixel is output, no javascript at all. This is the fallback method should a visitor have javascript disabled. You would be enabling it for all visitors. It will not conflict with other script on your page. Pixel helper may complain, but it should work in FB itself.

    FYI, when posting code as reference in these forums, it’s much preferred you post usable text in a site like Pastebin or Gist. Images of code are not useful should your code need to be tested or used in corrected examples.



    Hi bcworkz.

    Thanks for the answer. I waited 4 days and finally, Facebook detects its pixel implemented correctly. I did not change anything. Looks like Facebook needs more time than Analytics to check its pixel.

    Anyway, thanks!

    • This reply was modified 11 months ago by  jlcule.
    Moderator bcworkz


    You’re welcome. 4 days!! That’s good to know in itself. This topic would likely help others, thanks for reporting back.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Error adding FB Pixel to functions.php’ is closed to new replies.