Are you looking into retargeting ads on Facebook? Do you want to install the Facebook pixel in WordPress?
Setting up Facebook Ad campaigns that are targeted toward people that have previously viewed your content is a great way to drive more traffic back to your site.
In this article, we’ll show you how to add the Facebook pixel in WordPress, step by step, to set up retargeting ads.
Why Use Facebook Retargeting Pixel to Boost Your Social Reach
Syed Balkhi, our founder and CEO, published a case study on how we boosted WPBeginner’s Facebook traffic by 332% in 2015. This sparked an overwhelming interest from our readers, who wanted to know how they can do the same for their websites.
When you boost Facebook page posts using Facebook ads, you can select a wide range of target audiences. Retargeting allows you to narrow your audience and get better results with less spending.
You can show your ads to people who are already interested in your website. These people are much more likely to respond to your boosted posts and advertisements on Facebook.
What is a Facebook Retargeting Pixel?
Have you noticed that after you visit a website, you start seeing its ads on Facebook? This is called retargeting or remarketing.
Those websites use Facebook’s retargeting technology, commonly known as Facebook Pixel or Meta Pixel.
The retargeting pixel does not add anything visible to your website. It simply sends a browser cookie to your visitors.
This allows Facebook to retarget users visiting your website on Facebook.
Let’s take a look at how you can add a Facebook retargeting pixel to your WordPress site.
Step 1. Creating a Facebook Retargeting Pixel (Meta Pixel)
To make it easy, we have created a video tutorial on how to install a WordPress plugin that you can watch below.
However, if you just want to follow text instructions, then you can follow our step by step tutorial on how to install Facebook’s retargeting pixel in WordPress.
First, you need to log in to your Facebook account and visit the Meta Business Suite. Then, click on All Tools » Events Manager.
Next, click on the ‘+ Connect to Data Sources’ button in the left-hand menu and select the ‘Web’ option.
After that, click the ‘Connect’ button.
In the next popup window, you need to enter a name for your pixel, which can be the name of your business or product.
Then, click the ‘Create Pixel’ button to continue.
Next, simply enter the URL of your website and click the ‘Check’ button to see if your site is eligible for integration with supported partners like WordPress and Shopify.
If your site is to be eligible for integration, you’ll see a green checkmark and you can click the ‘Next’ button to continue.
Next, you need to choose how to connect your website and send activity to Facebook.
For this tutorial, we’ll select the ‘Meta Pixel only’ option. You can always set up the Conversion API in addition to your pixel later.
Click ‘Next’ to continue.
Now, you need to select a method for adding the pixel code to your website.
If someone else manages the technical things on your website, then you can email them the pixel code. Otherwise, click on the ‘Install code manually’ button to install it yourself.
Facebook will now show you the pixel code that you need to install on your WordPress site.
Simply click the ‘Copy Code’ button to copy the pixel code, and we will show you how to install it in WordPress.
Step 2. Installing Facebook Pixel in WordPress (+ eCommerce Tracking)
You need to add the Facebook pixel code just before the </head> in your WordPress theme.
The easiest way to do this is by using the free WPCode plugin.
WPCode is the best code snippets plugin for WordPress. It makes it easy to insert code into your WordPress site’s headers and footers without needing to edit your theme files.
To get started, you need to install and activate the WPCode plugin. For step by step instructions, see our guide on how to install a WordPress plugin.
After installing and activating the plugin, you need to go to the Code Snippets » Header & Footer page.
Then, simply paste the Facebook pixel code into the Header box.
When you’re finished, don’t forget to press the ‘Save Changes’ button.
See our guide on how to add header and footer code in WordPress for detailed instructions.
With that, you have successfully installed Facebook pixel on your WordPress website.
Alternative: Adding Facebook Pixel for WooCommerce with eCommerce Tracking
If you have an online store, you can upgrade to the premium version of WPCode to add eCommerce tracking pixels and improve your ad performance.
WPCode’s Conversion Pixels addon allows you to easily add eCommerce tracking pixels for popular platforms like Facebook, Google Ads, Snapchat, Pinterest, and TikTok in 1-click.
It seamlessly integrates with WooCommerce and Easy Digital Downloads, so no additional setup is required.
You can quickly choose which eCommerce events to track, such as product page view, add to cart, checkout, and purchase, so that you can better understand how your ads are performing and improve your return-on-ad-spend (ROAS).
First, you need to install and activate the premium WPCode plugin. You need the Plus plan or higher to access the Conversion Pixels addon. For step by step instructions, see our guide on how to install a WordPress plugin.
After that, follow the same instructions in step #1 to create a Facebook pixel for WooCommerce.
Next, copy the pixel ID, which you can find under ‘Data Sources’ in the Facebook Events Manager of your Facebook Business account.
Then, go to Code Snippets » Conversion Pixels from your WordPress dashboard, and paste your pixel ID into the ‘Facebook Pixel ID’ field.
After that, you need to add your Facebook Conversion API Token to set up eCommerce tracking.
To do that, go back to the ‘Data Sources’ screen from the Facebook Events Manager and click on your pixel. With your pixel selected, click on the ‘Settings’ tab, and then click on the ‘Generate Access Token’ link.
After clicking the link, your access token will be automatically generated. Simply copy the access token and paste it into the ‘Conversions API Token’ field in WPCode.
Now, you can scroll down the page to choose what type of eCommerce events to track.
By default, all events tracking is enabled. But, if you want to turn off events tracking for any of the options, simply toggle the switch to ‘Off.’
Don’t forget to hit the Save Changes button at the bottom of the page.
That’s it, you’ve successfully added the Facebook pixel for WooCommerce and you’re ready to track eCommerce events.
Step 3. Creating Custom Audiences Using Facebook Pixel
Now that you have successfully installed Facebook Pixel on your WordPress site, the next step is to create custom audiences for your retargeting campaigns on Facebook.
Custom Audiences allow you to target users you already know for your Facebook ads. These users can be your website visitors, users who like your page, or users who signed up for your mailing list.
Here is how you can create custom audiences on Facebook.
Simply visit the Meta Business Suite dashboard and go to the All Tools » Audiences section.
On the next page, click on the ‘Create a Custom Audience’ button.
This will bring up a popup where you need to choose the audience source you want to target on Facebook.
You can choose your website, customer list, app activity, and more. For this tutorial, we’re going to choose the ‘Website’ option.
After that, click the ‘Next’ button.
Now Facebook will ask you which website audience you want to target. You can choose all website visitors, people who visit specific pages, or visitors by time spent.
Next, you need to choose a duration of a number of days. Lastly, you need to provide an audience name. Use something that helps you easily identify this audience in your insights.
Once you are done, click on the ‘Create Audience’ button to finish creating your first custom audience.
Repeat the process to create more custom audiences by Facebook retargeting.
Step 4. Showing Your Ads to Custom Audiences Using Facebook Retargeting Pixel
The real fun begins with engaging your custom audiences by using Facebook ads.
Start by creating a new ad in Facebook. You can run different kinds of ads for different objectives. Like boosting your page posts, sending traffic to your website, increasing conversions, and so on.
Depending on what objective you choose, you will be able to select the target audience at some point during the ad creation.
In the same audience selection, Facebook will show you a custom audience, and you can select it to be targeted with your ad campaign.
We hope this article helped you install Facebook remarketing/retargeting pixel in WordPress. You may also want to see our guide on how to install and set up Facebook comments in WordPress and our expert picks for the best WordPress Facebook plugins to grow your blog.
If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.
crystal
Can you make an updated version of this? Now FB has a partners integration option. I have tried this version of doing (downloading a plugin) and I’ve tried their partners way of doing it and neither way is working for me.
WPBeginner Support
We will be sure to take a look
Admin
Jeff Cope
Thank you for the post and even though it does need updating since Facebook has changed the links and process, I finally added the pixel to my website. Note with the improvement in the WordPress Customizer, a plugin is no longer needed to add the pixel code above the /head.
WPBeginner Support
Thank you for your feedback and we still recommend the plugin to ensure it is included on every page on the site
Admin
Joseph Abokhai
I was using the Facebook for woocommerce plugin that automatically sets up a Facebook pixel on a particular website.
I started a new hosting account and redirected my domain name servers to point to the new hosting account.
My question is, since I changed my hosting account and started building the site from scratch, will the pixel still be attatched to my domain?
WPBeginner Support
Sadly, for that plugin, you would need to check with the plugin’s support for how they handle a change like that
Admin
Andrew Wilkerson
Well I think it’s done right, thanks WpBeginner! Still not sure what I should be doing with the second bit of code from Facebook in order to track people who have gone to one particular page. I clicked around for over 2 hours on FB then my wp site, then gave up as usual.
I’m not even sure how this works, where does the headers and footers plugin put the code, in to every page? Do I just add the second bit of FB code beneath this? it needs to go after the . Does it go in the page template? Posts template? I’m lost as usual, until FB make this easier I’m not going to bother. Selecting your audiences, demographics, countries, Events? and all that, it’s just too overwhelming for most business owners. Those who have money will survive online, they can pay someone else to do it, one-man businesses like mine will eventually disappear. I can’t make any money wasting time on things like this so it just gets worse. Already slipped off the first page of Google after 14 years on there, all down hill from here I’m afraid, time to do something else.
Angie Sherbondy
Thank you! I followed the instructions. I already had headers and footers installed and there was already code in the header section so I put this above it. Is that OK?
Thanks,
Angie
Shivam Bhateja
Yes, it is okay. I used the analytics code and pixel code both in the headers section.
Shodkk
Ya, there is no Problem in doing So. It is Completely Fine this only a Code.
This Code load each time when your site page run. there is no problem in that OK. Both Code run and send the Respected data back to FB and Google by their Respective code.
Andre
Hi there. There is one question that I have on the FB pixel I just can’t seem to find an answer for anywhere. Shopify has an app called Trackify that allows you to segment the events, per product for example, and in doing so allows you to super target people who have purchased a particular product without setting up custom events. Is there a similar plugin for Wordpress. Please if you could help that would be great! I am at my wits end with searching for a solution.
Maryann
I am so glad I came across your site. Very helpful and informative.
Thank you
vinton samms
Thank you most kindly for this tutorial. I really did not how how to use the FB pixel. Thanks again.
Vinton
Nathan
I’ve installed the pixel using the plugin.
Will the pixel automatically be place on every page?
Thanks
Claudio
It seems like Facebook has changed some of the details for doing this since this post was written. They now have a new pixel which also includes having to copy event code. How/where do we do this within the context of this article and plugin?
Matthew
How do you install the pixel to fire on page load given the plugin constraint?
I’ll clarify- Facebook states that if you want an event to fire on page load the code for that specific event has to be pasted BELOW the head tag.
The plugin in you recommend, as well as all the others I’ve seen available for WP, don’t address this issue.
Recommendations?
John Henry Gaspay
Is it also possible to add the code on the footer instead in the header portion? usually if it’s for tracking purposes better implementation would be on the footer part, your know for SEO purposes.
Pat
I went ahead and installed the pixel because i wanted more visits to my music site. I started filling in the remarketing stuff in FB, then I came to the part about paying! I didn’t realise I had to pay so I’ve uninstalled the remarketing pixel in WP and delete everything in FB that I’d filled out. I hope I don’t start getting demands for money. Maybe you could add a note to your article that there will be payment involved in FB marketing. I guess I should have realised.
Jim
You didn’t think you had to pay for marketing or advertising? Where have you been for the past one thousand years?
Michael
Is there any way to use a Facebook pixel if I am at wordpress.com?
WPBeginner Support
Please see our guide on the difference between self hosted WordPress.org vs free WordPress.com blog.
Admin
Alex
Great article! Thanks
I use wordpress on mys ite – I’ve managed to install the facebook pixel using the “insert headers and footers app” and facebook says it is successfully installed
in wordpress, what’s the best way to install a standard event code? I have a “thank you” page that I would like to use as my conversion referecence – the thank you page appears after the viewer has submitted a form
Thanks!
Karl
I have also successfully installed the facebook pixel code through insert headers and footers by wpbeginner, now I want to know how to add standard event codes. Can anyone teach us how to? Big thanks to WPBeginner for this
Terry Green
I added the FB retargeting pixel about a month or so ago to my WP site, and the Facebook Pixel Helper showed it was installed and working. Now I “hear” there is a new Facebook Pixel, AND my Facebook Pixel Helper shows “there are no Facebook pixels” on my site.
The article I read goes all over the world and back about everything I don’t want to know about. All I want to know is how to replace the pixel. You are a trusted source so I thought I would ask … is there a new pixel out? And can I add it (or replace the old one) as easily as it was to add it the first time (with a plugin), or will it require manually adding code to each page?
Nina
How do we add other rules, like these Search fbq(‘track’, ‘Search’);
Add to cart fbq(‘track’, ‘AddToCart’);
Add to wishlist fbq(‘track’, ‘AddToWishlist’);
do we simply add it to the code?
Yev
I need to re-copy the Facebook pixel if I add standard/custom events for Conversion Tracking, to paste the new one into the website.
Does that mean I only have PageView data up until I update the code on the website, or does any type of data backtrack and becomes available as long as I had the original/basic Pixel installed?
Darren
Hi,
I have done this and the Facebook pixel is tracking. However I am using the sign up form as well with the mailchimp API and I added the Lead and Complete registration aspects to the pixel in the header. They are firing as the chrome addon shows that however the sign up form isnt triggering as a sign up or registration complete. I am not sure if I am explain my problem well. So in business manage and the pixel I can see people visiting my site. But when they sign up the value for lead or complete registration is still 0. Any ideas why this occurs? I used the old FB conversion pixel and that was fine just this new one is so annoying!
Cheers
Ron Hudson
Wow! Thank you very much for writing this post and recording a video to help your audience implement this important tool.
WPBeginner Support
Glad you found it helpful.
Admin
Prakash Thakur
hi wp beginner
Great job by making this article..
one question only…
can i uninstall that plugin after uploading script in the header section???
Brendon Osborne
Great video, super simple and helpful!!
moon
Hi,
I need to add ” Facebook Pixel Code ” in my wordpress site.
May I know if this plugin suitable for it.
Thanks
Elle Van Buren
Dear author, I have a question on the “Add conversion tracking” feature. Like you instructed, if we place the Facebook pixel into the header section of the plugin, that piece of code will be on every page. But if I have a conversion page, how do I single out that particular page and add in a custom event such as fbq(‘track’, ‘Lead’); to the middle of the Facebook pixel?
Usually with Wordpress or other CMS, once something is in the header, it is on every page. How do we then put up something different for a particular page?
Thanks!
I Have The Same Exact Question!
I have the same question! How do you I single out a particular page (Thank You Page) and add in a custom event?
Marvin
I too have this question.
Stephen
Has anyone gotten a solution for this?
Adrien
Still have this question remaining… any solution ?
Cheers
Luke
THANK YOU!
So much easier to understand than the official FB instructions.
Hammad Afzal
Great article, Can I use this feature right away or first I have to buy facebook ad campaign. I means paid Facebook advertising.
Thanks alot syed balkhi for a cool post.
WPBeginner Support
You can see information about your visitors right away. You can run a paid campaign later on.
Admin
Hammad Afzal
Thank you so much
fajar siagian
hello
i want to ask about this
is this using facebook ads first. become subscriber user facebook ads
thank you,
Kingsley
Great, thanks for this tutorial
Angelica Costa
This is perfect. I am starting to experiment on Facebook Ads.
On other note, is there a way to tell where are facebook visitors coming from? Sometimes I get a load of new user and have no idea who shared a link to my website.