Inject Facebook or Google Pixels into the Head Section in WordPress
Last modified: June 3, 2026
Add the above to the functions file and switch the “PIXEL GOES HERE” with the pixels you need to inject to the head of your WordPress site.
add_action('wp_head', 'inject_into_head');
function inject_into_head(){
?>
<!-- Facebook Pixel Code -->
PIXEL GOES HERE
<!-- End Facebook Pixel Code -->
<?php
};
Show More
* This button will show the rest of the post and open up an offer from a vendor
Final Word: Injecting Facebook and Google Pixels
Adding tracking pixels to the WordPress head section gives you full visibility into how visitors interact with your site across Facebook and Google’s advertising platforms. Once your pixels are in place, check that your Open Graph tags are also correct so that when posts are shared on Facebook, the right thumbnail appears. See our guide on how to fix the Facebook incorrect thumbnail issue in WordPress for that related fix.
Save 4 Later
Email liked links to yourself

Website Maintenance – Use Promocode: scanwp
Advanced JetPlugins for Elementor
Semrush 14 days trial
Kinsta – Managed WordPress Hosting
Bluehost Hosting