Campaign setup, budget and delivery

How do I set up the Meta Pixel on a WordPress site?

Pick one install route, keep one copy of the code, and fire the Lead when the form is saved. The WordPress setup that keeps Meta and your CRM in agreement.

Published

Setting up the Meta Pixel on WordPress takes one install route and one copy of the code. Print the base code in the head of the site, fire the Lead once the form submission has been saved, and share the event ID with your server side so the two copies pair instead of counting twice. The route you choose matters less than keeping a single copy running.

Pick one install route

WordPress offers four realistic places for the base code. They differ in who can maintain them, not in what Meta receives.

RouteWhere the code livesBest forWatch out for
Theme templateprinted on the wp_head hook in the themea site you control with one themea theme update or a replacement wipes a hard-coded edit
Code snippet pluginthe site’s own snippets screen, head sectionthe usual middle ground, no theme editingtwo snippets doing the same job
Meta Pixel plugin or a form plugin with a Meta settingthe plugin’s settings screenteams without a developerthe plugin may fire events on its own, next to yours
Google Tag Managera container tag firing the base codesites that already load a containera tag held back by triggers fires late, or never

Whatever you pick, the requirement is the same as in Meta Pixel setup: the base code has to load in the head, before the page has content worth reporting. Meta’s own note is that placing it between the opening and closing head tags reduces the chance that browsers or third party code block its execution.

Create the Pixel before you touch the theme

  1. Open Events Manager and look under Data sources before creating anything. If the site already has a Pixel, use it, because Meta wants the same ID on browser and server events.
  2. Create the dataset if there is none. Meta calls the procedure creating a dataset for your Meta Pixel: one object, two names, one ID that goes in the base code and in every Conversions API request.
  3. Decide which business owns it. An agency should create it in the client’s portfolio, so the data stays with the business that paid for it when the contract ends.
  4. Copy the base code and note the ID, which is the same string in the snippet and in the server request path.

On WordPress the ownership question comes back through plugins, because a plugin connects to whichever Pixel the account that installed it can see. Install it with an account that has access to the right portfolio, not with a personal login that later disappears.

Fire the Lead from the form, not the click

The common WordPress shortcut is to hang fbq('track', 'Lead') on the submit button. On a lead form a click is not a lead: it fires when validation fails, a double tap on a slow connection fires it twice, and the server can still reject the submission as spam. Each of those adds a Lead to Meta’s count with no lead in your system, and all of them train the delivery system.

Fire it after the submission is saved:

  1. Find the hook your form plugin runs after a successful submission, and check that it only runs on success.
  2. Generate the event ID on the server, one per submission, and store it with the lead row.
  3. Print the browser call in the success state, passing the ID as the fourth argument, and send the same ID from your server route.
  4. Use one event per form. Lead is defined by Meta as a sign up completed, and adding CompleteRegistration and Contact for the same form gives you three numbers to reconcile.
  5. If your design fires from a thank-you page instead, make sure only a successful submission can reach it and that a refresh does not send a second Lead.

The event ID is the part people skip, and it is the part that makes the rest work. Meta pairs a browser event and a server event when the IDs and the event names match, inside 48 hours, keeping the first copy it received and favouring the browser copy when the two arrive within five minutes of each other. Generate the ID once, in one place, and pass that string to both sides. The pairing rules are in Pixel and CAPI deduplication.

Keep the server copy in the same family

A WordPress site can send the Lead from the server through a plugin that posts to the Graph API, a server-side Tag Manager container, or a small hook in a plugin of your own. Whichever you use, the entire point is that a blocked browser does not erase the lead, and the route comparison is in the Conversions API on WordPress.

Two habits keep the pair honest. Keep the access token in wp-config.php or an environment variable, never in theme JavaScript. And do not hash the fbc and fbp values, the IP address or the user agent, which Meta expects in clear, unlike the email and phone.

What breaks on a WordPress site

  • The same code twice, a plugin plus a hard-coded snippet, so every event fires twice. Duplicate Pixel code sits at the top of Meta’s list of common setup errors.
  • An old Pixel from a previous agency still installed, which receives a copy of every tracked event.
  • Automatic event detection left on beside a coded Lead, which Data Advisor can show as an Auto-detected event next to yours.
  • The base code in the footer or behind a delayed tag, so the PageView arrives late.
  • Different Pixel IDs in the browser and on the server, which leaves nothing to deduplicate.
  • A caching plugin serving a page where the consent banner does not load first, so events fire before anyone chose.

Test before you trust the numbers

In Events Manager open Data sources, choose the Pixel, then Test events. Submit the form on the live site with your own email and phone, and watch for the Lead arriving with the parameters you expect: event name, event ID, and the browser copy marked as deduplicated. Then submit again and refresh the confirmation screen. One lead in, one Lead counted.

Keep the number of test submissions small. Events sent with a test code are not dropped: they flow into Events Manager and are used for targeting and measurement.

When the WordPress form is only one of several lead sources, the counting gets harder than the code, and Meta Pixel, Conversions API and attribution collects the rest of the questions. DropCPL removes the WordPress side of this from the loop for the landing pages it serves: the click is logged first-party on your domain, and each lead goes to Meta server-side with an event ID, the fbc and fbp values, and the ad that produced it attached to the record.

Questions on this topic

All questions on this topic →

FAQ

Should I use a plugin or paste the code myself?+

Either works, and the difference is not accuracy but maintenance. A plugin survives a theme update and adds a settings screen; a snippet in the theme template gives you control over where the code sits and breaks when the theme is replaced. What matters is that only one of them runs, because a plugin plus a hard-coded snippet fires every event twice.

Where does the Pixel code go in WordPress?+

In the head of every page you track, which in WordPress means printing it on the wp_head hook, or in the head section field of a code snippet plugin. Meta recommends the head because a code placed in the footer or behind a delayed tag fires the PageView late, or not at all for visitors who leave quickly.

Why does Events Manager show more leads than WordPress has form entries?+

Usually because the Lead fires on the submit button click or on the thank-you page, so failed validations, double taps and refreshes each add a Lead. Fire it once the form submission has been saved, and give the event an ID tied to that submission.

Do I need the Conversions API on WordPress too?+

The Pixel alone loses events that ad blockers and browser limits stop. A server route on WordPress is a plugin that posts from the server, a server-side Google Tag Manager container, or a small hook that sends the Lead from PHP. Pass the same event ID to both sides so Meta pairs them instead of counting the lead twice.

Does my cookie banner block the Pixel?+

It depends how the banner is built. One that holds back the base code sends nothing until consent, while one using Meta's consent API pauses and resumes the same code. Test the decline path and the accept path separately, and expect fewer Leads in Events Manager than forms received when a share of visitors decline.

Ready to find out what
converts, for real?

Free to start.

Start free →