If you have a WordPress website and you want to use Google Analytics, a Facebook Pixel or a Cookie Script, then you’re going to need to add a little bit of code to your website.
However, if you aren’t familiar with writing code, then this might seem a little daunting.
In this article, I’m going to show you an easy way to add code into your header or footer without writing any code at all, or editing any of your theme files.
Easy Ways To Add Code In WordPress
There are three ways for you to add code to your WordPress website.
- Manually Entering Header & Footer Code Into WordPress
- Entering Code Into WordPress Via Built-In Theme
- Entering Code Into WordPress Using a Plug-in
Doing it manually might require a little coding know-how. You have to edit your themes header.PHP, and footer.PHP files, which probably sounds quite complicated and a little risky if you aren’t sure what you are doing.
These can also get overwritten if your theme gets an upgrade, so if this is likely to happen then it might not be the best route to go down.
You can also do it through your themes built-in header and footer code feature, it’s worth checking if your theme has the functionality built-in already.
You can do this by going to your dashboard >login and then go down to appearance and then customise. Over on the left, there may be an option to add in header and footer scripts.
If not then the third way, and the one that I’m going to explain, is to add code in via a plug-in.
To do this you will go to plugins then add new. You can then use the search bar to search for header and footer script and click on the WPBeginner option. This is the one that I use on all my websites, and it has over one million active installations, so that’s a good sign that it’s a really good plugin.
Then click on install and then activate to add the plugin to your website.
How To Enter Code to Your Website
Once the plugin is installed and activated, you need to go to settings and then down to the new menu item then click on insert headers and footers.
There are three options here to add:
- Script into the header
- Script into the body
- Script into the footer
If a script tells you to add it after the body tag, then you would add it into the body section.
So let’s take Google Analytics for example. If you want to install Google Analytics on your own site, then you just need to go to analytics.google.com and register and set up your account.
Once you’ve done this, you can click on admin down on the left-hand side of Google Analytics and then into tracking info and then tracking code.
You’ll get a little bit of script in there that says: “Copy and paste this as the first item into your head of every webpage you want to track.”
It’s important that it’s first as you want to track everything that happens on your websites, so you don’t want any other scripts interfering with it. The only thing that would go before it is cookies, as they have priorities over all the scripts so that people can opt out of being tracked.
Copy the tracking code and then go back to WordPress and insert the code into the plugin header. You don’t need to put it on every web page as the plugin does this for you.
You can add more than one script depending on what you are wanting to track. It’s common to have Google Analytics, Google Search Console, Facebook pixel and others such as Pinterest.
And it’s as simple as that. The next time you want to add in a script it will only be a 30-second job!
Please let me know if you have any questions below!