Sign inDocsBlogAboutSupportContact
Analytics

Add Meta Pixel (Facebook Pixel) to WordPress without a plugin

Pixel ID in hand, one command installs the full Meta Pixel. Standard events fire automatically. Retargeting audiences start building immediately.

3 min read May 2026 enable fb pixel

The WordPress way to install Facebook Pixel is clunky

You run Facebook or Instagram ads. Without the Meta Pixel on your site, you can't build lookalike audiences, can't retarget site visitors, and the ads optimize toward clicks instead of conversions.

The canonical WordPress paths are: install an analytics plugin (comes with admin pages, updates, subscription nags), paste the snippet into functions.php (breaks when you switch themes), or set up Google Tag Manager as middleware (overkill for one pixel).

What most people do instead

Install a dedicated Facebook Pixel pluginYet another plugin. Admin page, settings, update nag. Some have premium tiers to unlock basic features.
Paste the tracking code into functions.phpTied to the active theme. Switch themes → tracking disappears. No conditional logic.
Set up GTM as middlewareAdds another layer. GTM itself has to be installed. Overkill if Facebook Pixel is the only thing you need.

How to add the Meta Pixel to WordPress without a plugin

You can drop the Pixel base code in yourself. A must-use plugin that prints it on wp_head does the job:

// wp-content/mu-plugins/meta-pixel.php
add_action( 'wp_head', function () { ?>
  <!-- Meta Pixel Code -->
  <script>
    !function(f,b,e,v,n,t,s){if(f.fbq)return;n=f.fbq=function(){n.callMethod?
    n.callMethod.apply(n,arguments):n.queue.push(arguments)};if(!f._fbq)f._fbq=n;
    n.push=n;n.loaded=!0;n.version='2.0';n.queue=[];t=b.createElement(e);t.async=!0;
    t.src=v;s=b.getElementsByTagName(e)[0];s.parentNode.insertBefore(t,s)}(window,
    document,'script','https://connect.facebook.net/en_US/fbevents.js');
    fbq('init', '1234567890123456');
    fbq('track', 'PageView');
  </script>
  <noscript><img height="1" width="1" style="display:none"
    src="https://www.facebook.com/tr?id=1234567890123456&ev=PageView&noscript=1"/></noscript>
<?php } );

Replace the ID with your Pixel ID from Events Manager and it starts firing PageView. The catches are familiar:

  • A theme switch drops a functions.php version. Use mu-plugins to avoid that.
  • The ID lives in a file, with no interface to change it.
  • It fires for logged-in admins, polluting your audiences and conversion data.
  • No consent gating, which is both a GDPR and a Meta policy concern.

The command does this in one step, with consent-awareness and page conditions, and no file to babysit.

A better way: one command, one ID, tracking live

Run enable fb pixel with your Pixel ID. The command auto-registers as a startup command so the tracking snippet outputs on every page load. No theme edit, no plugin, no GTM middleware.

TrueCommander
Facebook Pixel enabled
Tracking live on next page load
Pixel ID: 1234567890123456
Registered as startup commandactive
Consent-aware: optional flagGDPR-friendly

Shown in advanced mode, where commands start with tp. In easy mode you type the same command without the tp prefix.

Consent-aware flag included. Pass -consent_aware=true and the pixel only fires when your cookie-consent plugin's gate has been accepted. Works with any standard WP consent plugin that sets a cookie flag.

How it works

The command hooks wp_head with the Meta-provided tracking snippet, then auto-registers itself in Startup Commands so the tracking stays active across requests. Re-running with a different ID updates the existing entry. Disable from Startup Commands to remove.

1
Get your Pixel IDMeta Events Manager → Data sources → Pixel
2
Run the command with the IDtp enable fb pixel -pid=1234567890123456
3
Verify in Meta's dashboardFacebook Pixel shows tracking events within minutes
ParameterValue
-pid (required)Pixel ID (format: 1234567890123456)
-consent_awaretrue to only fire after cookie consent (checks standard consent cookie)
ScopeAuto-registered as startup command, runs on every frontend page load
Where to find the IDMeta Events Manager → Data sources → Pixel
Can be used in

Real example

You spent $400 on Facebook ads for a product launch. The ads converted poorly because Meta couldn't optimize without conversion data, the pixel wasn't installed. Run tp enable fb pixel -pid=1234567890123456, relaunch the campaign a week later, and Facebook optimizes toward buyers instead of clicks. ROAS triples.

Goes further with TrueCommander

Frequently asked questions

Ready?

Facebook Pixel tracking in 30 seconds.

This is one of 91 commands. All included with every license.

Cookies. The short version.

Essential cookies keep the cart and theme working. Analytics only fire if you say yes. Read our policy.