Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jfeliweb/a416433eab155ae671b537accfac3cbf to your computer and use it in GitHub Desktop.
Save jfeliweb/a416433eab155ae671b537accfac3cbf to your computer and use it in GitHub Desktop.
- First, I would log in to my Facebook Ads Manager account and navigate to the Facebook Pixel section.
- Next, I would create a new custom audience for the specific pages where I want to track pixel events.
This can be done by selecting the "Custom Audience" option from the Audiences menu, and then choosing the
"Website Traffic" option.
- In the Website Traffic section, I would select the "Add a rule" option and then specify the pages I want to
track using the "URL contains" rule. For example, if I want to track all pages in a "blog" category,
I would enter "/blog/" in the URL contains field.
- Once I have created the custom audience, I would copy the Facebook Pixel code provided by Facebook.
- In WordPress, I would navigate to the header.php file of the theme I'm using. This file is usually located
in the /wp-content/themes/your-theme-name/ directory.
- I would then find the closing </head> tag and paste the Facebook Pixel code just above it. This ensures that the
Pixel code loads on every page of the site.
- Finally, I would modify the Pixel code to include a conditional statement that checks if the user is on
one of the specific pages I want to track. For example, if I want to track all pages in the "blog" category,
- This code checks if the user is on a page in the "blog" category and only loads the Facebook Pixel code if they are.
This ensures that the Pixel is only fired on the specific pages I want to track, and not on every page of the site.
<?php if (is_category('blog')) { ?>
<!-- Facebook Pixel Code for blog category -->
<script>
// Paste your Facebook Pixel code here
</script>
<?php } ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment