Adding Facebook Pixel Code To Your WordPress Website Without A Plugin
One of the things I’ve learned over the years working with the WordPress platform is that less is more.
WordPress has a huge learning curve, one that even those who are proficient in HTML and CSS languages have a challenging time picking up. It’s not because it’s difficult. It’s just different.
Once you get started with WordPress you will soon find out that you can pretty much add just about any imaginable functionality to your website with “PLUGINS”. It’s easy. You need to have a contact form in your contact page? There’s a plugin for that. Oh, you want to add social share buttons to your site? You sure will find a plugin for that too. Oh, what about an instagram feed? Yup, you’ve got it, there’s a plugin for that too!
Plugins are the answer to everything. We can thank the developers that dedicate their time to do just that. It saves a lot of time and headaches for those who are not savvy with PHP, CSS and HTML. For me, personally, I use them as a last resort…after anything I try with writing code becomes more time consuming than what I want to spend on a website.
There is a down side to plugins. Some of the free plugins available on the WordPress repository could be plagued with errors, and quite often those errors could leave open doors that compromise the security of your website. Additionally, some plugins that are poorly or carelessly written end up making unnecessary requests to your database thus slowing down your website. Lastly, we are at the mercy of the developers who took their time to develop a plugin and then add it to the WP repository – sometimes they abandon the project and move on which means that as WordPress progresses with updates, the plugin is not kept up. This causes compatibility issues that could potentially break your website!
In any case, if you are serious about your marketing efforts and want to use another tool besides the “jetpack” plugin, you could add the Facebook pixel to your WordPress website. And you don’t have to use a plugin or know too much coding! You just have to be cautious and pay very close attention to what you are doing!
Ready? Here we go!
- Make sure you create a backup of your website! You can do this via your hosting plan. If you don’t have access to this information ask your developer or designer for it. Having access to all your files is imperative! (I always stress this to my clients!).
- Obtain your Facebook pixel code. This page walks you through the steps on how to create a FB pixel. Note: You will need a Facebook business page/account.
- Copy your pixel code once it’s generated.
- Go back to your WordPress dashboard and navigate to your Appearance >>> Then click on “Editor”.
- Take a deep breath…you’ve made it and now you are looking at code! Isn’t it a beauty!
- Ok…moving on. If you are using a parent theme, all the files should appear listed on the right column. If you are using a child theme, go to the top of the right column. There is a pull down menu. Select the parent theme of the child theme you are using. (Learn more about why you should use a Child Theme here).
- Find the HEADER.PHP file. In some instances it will be titled THEME HEADER. Click on it.
- More code! Beautiful! 🙂
- Somewhere in the text of the file named header.php you will find an opening tag like this <head> and a closing tag </head>. This is where any scripts that your website needs to include in every page will go, such as your Facebook pixel code, google analytics, google fonts, etc.
- Right before the </head> (and after any code that’s there), paste your pixel code.
- Click on ‘UPDATE FILE’ at the bottom of your page.
- That’s it! You have successfully inserted your pixel code into your website!
How do I know my pixel code is working? What to do next?
Your pixel code will take some time to gather the data. You can find out if it’s active by going to the Pixels tab on your Ads Manager account where you should be able to see a green light to let you know your pixel is active. A red light means it was not properly implemented or it is still gathering information. While you are on that page you can also learn more about the many uses of a pixel code for your advertising and marketing campaigns.
Best of luck!
Great article – an easy step by step plan!
But being a complete facebook novice my add people ask me to add some events to my woocommerce pages (product pages and then some other events to my cart and the final “order in” page ?
Any ideas to how I add those
Hi. There is a way to add these to your woocommerce pages. There’s the “easy” way, which is adding the Facebook for Woocommerce plugin. This will add the necessary events to all your woocommerce pages. But you already know I don’t like plugins and do it the hard way. LOL.
You need to first copy the woocommerce pages that need to record the events…for example, I add the “purchase” event code to my “thankyou.php”. So I copy the thankyou.php page into my child theme as it is not recommended to edit the plugin pages directly.
Sometimes your theme might have modified those pages so be sure to check inside the parent theme/woocommerce folder first to see if the pages that need the code are there. In which case, that’s the page you need to copy instead of the one inside the plugin.
If I made ZERO sense, feel free to email me directly!