1. Documentation
  2. How to
  3. Install Meta Pixel

Install Meta Pixel

Adding Meta Pixel to your WordPress site helps you track user interactions and optimize your Facebook ads. Here’s a straightforward guide to achieving this without any hassle:

Method 1: Using a plugin

PixelYourSite is a freemium plugin that makes it easy to add and configure Meta Pixel and other tracking platforms like Google Analytics and Pinterest Tag.

Install the plugin:

  1. Go to your site admin area.
  2. Navigate to Plugins -> Add New.
  3. Search for “Pixelyoursite“.
  4. Install and activate the plugin.

Configure the plugin:

  1. In the left menu, click on PixelYourSite.
  2. Locate the Meta Pixel row and push the Click for settings button.

Method 2: Adding code via theme’s functions.php

This method requires having the child theme installed and activated – learn how to install the child theme. Using a child theme’s functions.php file allows you to add Meta Pixel code without directly modifying the theme. Here’s how to do it for our themes:

  1. Go to your site admin area.
  2. Navigate to Appearance > Theme File Editor.
  3. Ensure that your active child theme is selected from the dropdown in the upper-right corner.
  4. On the right side, find and click on Theme Functions (functions.php).
  5. Scroll to the bottom of the functions.php file and add the following code snippet:
function add_meta_pixel_code() {
    ?>
    <!-- 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', 'YOUR_PIXEL_ID');
      fbq('track', 'PageView');
    </script>
    <noscript><img height="1" width="1" style="display:none"
      src="https://www.facebook.com/tr?id=YOUR_PIXEL_ID&ev=PageView&noscript=1"
    /></noscript>
    <!-- End Meta Pixel Code -->
    <?php
}
add_action('keydesign_head_bottom', 'add_meta_pixel_code');

Important: replace YOUR_PIXEL_ID with your actual Facebook Pixel ID.

Following these steps ensures your WordPress site is integrated with Meta Pixel, allowing you to track user actions and enhance your advertising efforts effectively.

Was this article helpful?