Struggling with how to add Facebook Pixel to WordPress? Just like adding Google Analytics tracking to WordPress, Facebook Pixel can throw you for a loop if you’re not super tech-savvy.
But don’t worry - it’s really not all that difficult. And in this post, I’m going to show you exactly how to add Facebook Pixel in no-time so you can start optimizing your Facebook ad campaigns.
To accomplish that, I’ll do two things:
- Show you the quick and dirty method of adding the basic Facebook Pixel code in WordPress
- Tell you about a couple free plugin that can help you add the Facebook Pixel code and let you manage custom audiences and conversion goals directly from your WordPress dashboard.
What is Facebook Pixel?
If you just want the guide, skip this section and go straight to the next one.
But because Facebook Pixel isn’t nearly as ubiquitous as Google Analytics, I want to lead with a quick introduction to what this thing is (and whether or not you actually need it).
Basically, Facebook Pixel lets you track the actions of everyone who visits your site while simultaneously logged into Facebook (via cookie). If you think about it...that’s much pretty everyone on the Internet nowadays.
You can use this data to do two things:
- Retarget your visitors with Facebook ads based on specific actions they took on your site. For example, you could target all users who “visited Page X” or “Added a WooCommerce product to their cart”.
- Track conversions from your Facebook ads. Optimize your ad spend with detailed conversion tracking.
If you’re running Facebook ads, you should absolutely install Facebook Pixel. But if you’re not (and never plan to), Facebook Pixel isn’t something you need to worry about right now.
How to Add Facebook Pixel to WordPress
To add the basic Facebook Pixel tracking code to your WordPress site, all you need to do is:
- Create a Facebook Pixel in your Facebook Ads account
- Add that code to the <head> section of your WordPress site.
Here’s how to do both of those things…
Step 1: Create a Facebook Pixel in Facebook Ads Manager
To create Facebook Pixel, you need to head to your Ads Manager dashboard and go to the Pixel tab. Rather than trying to search around for it, just head to this link to be taken straight there.
Once there, click the Create a Pixel button:
That should open up a window. In that window, you just need to enter a name for your Facebook Pixel and then click Next:
Then, you should see an option to grab the code. Choose the Copy and Paste the Code option for the basic Facebook Pixel tracking:
Then, you should see some raw tracking code. Save this because you’re going to need it in the next section!
Step 2: Add Facebook Pixel Tracking Code to WordPress Header
Now that you have your code, you need to add it to your WordPress header right before the </head> code. Ok - how the heck do you do that?
One way is to just dig into your site’s header.php code and paste it in. But, that’s not always easy for beginners. And if you ever switch themes, you’d need to go back and add Facebook Pixel again (and hope you didn’t forget about it!).
For those reasons, I’m going to show you how to do it using WPBeginner’s Insert Headers and Footers plugin. It allows you to add code snippets to your theme’s headers without needing to even look at a single line of code.
Once you install and activate Insert Headers and Footers, head to Settings → Insert Headers and Footers and paste in the Facebook Pixel code to the Scripts in Header box:
Make sure to save your changes.
Then, you can verify that Facebook Pixel is properly installed by using the free Facebook Pixel Helper Chrome extension from Facebook (or just looking at your source code):
What If You’re Using a Template With No Header?
This question might have seemed silly a few years ago, but now that page builders like Elementor allow you to build pages with truly blank canvases, you might be wondering whether or not Facebook Pixel will still fire with the method I outlined above.
So, I decided to test it with Elementor’s blank canvas feature. And even though Elementor isn’t loading the rest of my theme, it does still pull in Facebook Pixel from the Insert Headers and Footers plugin:
If you’re using a third-party landing page tool that doesn’t use WordPress, you’ll need to manually add Facebook Pixel to that landing page, though.
Plugins to Add Facebook Pixel to WordPress
In addition to the manual method I outlined above, you can also use a plugin to add Facebook Pixel to WordPress. I recently had a chance to play around with a few and I found a really nifty one called Pixel Caffeine.
In addition to helping you add the basic Facebook Pixel code, you can also use Pixel Caffeine to create custom audiences and conversion goals from inside your WordPress dashboard:
In order to do that, you will need to give Pixel Caffeine privileges to manage your Facebook Ads Account. But given that it comes from AdEspresso (one of the biggest Facebook ad management tools), I wouldn’t worry too much.
Just install and activate it, link up your Facebook account via Facebook Connect, and you’re off to the races. If you’re using WooCommerce or Easy Digital Downloads, you’ll especially love Pixel Caffeine because it includes built-in conversion tracking for those platforms.
Other Plugins to Add Facebook Pixel to WordPress
If you’d like a more lightweight plugin, Facebook Pixel Manager from Fatcat Apps lets you easily:
- Add Facebook Pixel to WordPress
- Hide Facebook Pixel from logged-in users
- Create Facebook Pixel Standard Events
There’s also a premium version with WooCommerce support and custom events.
I haven’t used this plugin personally, but I have used Fatcap App’s Google Analytics plugin and found it to be a well-coded, lightweight solution.
Wrapping Things Up
If you aren’t planning to get too crazy with custom audiences or conversion tracking, you should feel totally fine going with the first method I outlined. That is, using Insert Headers and Footers to paste in the Facebook Pixel code.
But if you are planning to rely on custom audiences and conversion tracking, Pixel Caffeine is a great option because it allows you to quickly create audiences and conversion goals based on WordPress data like taxonomies, custom fields, and more.
And if you want a lighter weight version of the same concept, Facebook Pixel Manager is another good option.
If you have any other questions about how to add Facebook Pixel to WordPress, leave them in the comments and I’ll try to help you out.