Trusted WordPress tutorials, when you need them most.
Beginner’s Guide to WordPress
25 Million+
Websites using our plugins
Years of WordPress experience
WordPress tutorials
by experts

How to Add Facebook Pixel in WordPress (+ eCommerce Tracking)

Editorial Note: We earn a commission from partner links on WPBeginner. Commissions do not affect our editors' opinions or evaluations. Learn more about Editorial Process.

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.

Adding Facebook Retargeting Pixel in WordPress

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.

Subscribe to WPBeginner

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.

Open Meta Business Suite and click on 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.

Connect to Data Sources in Facebook Events Manager

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.

Enter a name for your pixel

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.

Enter your website URL to create Facebook Meta pixel

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.

Choose how to connect your website Meta pixel

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.

Choose the option to install Facebook Meta pixel code manually

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.

Copy the code for the Facebook Meta pixel

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.

Paste Facebook Pixel in WPCode 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 Pro version

WPCode’s Conversion Pixels addon allows you to easily add eCommerce tracking pixels for popular platforms like Facebook, Google Ads, 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.

Copy Facebook Pixel ID

Then, go to Code Snippets » Conversion Pixels from your WordPress dashboard, and paste your pixel ID into the ‘Facebook Pixel ID’ field.

Paste your Facebook Pixel ID

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.

Generate access token for Facebook Conversions API

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.

Paste Conversions API Token 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.’

Enable or disable events tracking in WPCode

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.

Click on All Tools and choose the Audience option

On the next page, click on the ‘Create a Custom Audience’ button.

Click the Create 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.

Choose the source for your custom audience

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.

Choose the events for your custom audience

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.

Retargeting custom audience on Facebook

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.

Disclosure: Our content is reader-supported. This means if you click on some of our links, then we may earn a commission. See how WPBeginner is funded, why it matters, and how you can support us. Here's our editorial process.

Editorial Staff

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi with over 16 years of experience in WordPress, Web Hosting, eCommerce, SEO, and Marketing. Started in 2009, WPBeginner is now the largest free WordPress resource site in the industry and is often referred to as the Wikipedia for WordPress.

The Ultimate WordPress Toolkit

Get FREE access to our toolkit - a collection of WordPress related products and resources that every professional should have!

Reader Interactions

45 CommentsLeave a Reply

  1. Syed Balkhi says

    Hey WPBeginner readers,
    Did you know you can win exciting prizes by commenting on WPBeginner?
    Every month, our top blog commenters will win HUGE rewards, including premium WordPress plugin licenses and cash prizes.
    You can get more details about the contest from here.
    Start sharing your thoughts below to stand a chance to win!

  2. crystal says

    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.

  3. Jeff Cope says

    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 says

      Thank you for your feedback and we still recommend the plugin to ensure it is included on every page on the site :)


  4. Joseph Abokhai says

    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 says

      Sadly, for that plugin, you would need to check with the plugin’s support for how they handle a change like that


  5. Andrew Wilkerson says

    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.

  6. Angie Sherbondy says

    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?



      • Shodkk says

        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.

  7. Andre says

    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.

  8. vinton samms says

    Thank you most kindly for this tutorial. I really did not how how to use the FB pixel. Thanks again.

  9. Nathan says

    I’ve installed the pixel using the plugin.
    Will the pixel automatically be place on every page?

  10. Claudio says

    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?

  11. Matthew says

    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.


  12. John Henry Gaspay says

    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.

  13. Pat says

    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 says

      You didn’t think you had to pay for marketing or advertising? Where have you been for the past one thousand years?

  14. Alex says

    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


    • Karl says

      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

  15. Terry Green says

    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?

  16. Nina says

    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?

  17. Yev says

    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?

  18. Darren says


    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!


  19. Ron Hudson says

    Wow! Thank you very much for writing this post and recording a video to help your audience implement this important tool.

  20. moon says


    I need to add ” Facebook Pixel Code ” in my wordpress site.

    May I know if this plugin suitable for it.


  21. Elle Van Buren says

    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?


  22. Hammad Afzal says

    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.

  23. fajar siagian says

    i want to ask about this

    is this using facebook ads first. become subscriber user facebook ads

    thank you,

  24. Angelica Costa says

    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.

Leave A Reply

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.