How To Add Header & Footer Code To A WordPress Website

Adding a header and footer code to your Wordpress website can be daunting. When using Google Analytics, a Facebook Pixel or a Cookie Script, you are going to need to add a little bit of code to your website. In this video, 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.
Play Video
Kelly Sparkes Opal and Onyx Founder

Hi, I’m Kelly and I help female entrepreneurs translate their brand and message into a beautiful, responsive website, optimised to draw in and convert their ideal customer.

Signup to our


Video Transcript

Hey everyone, I’m Kelly, creator of the “Website Formula”, and today I’m going to teach 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.

If you have a WordPress website and you want to use Google Analytics or add your Facebook pixel or a cookie script, then you’re going to need to add a little bit of code to your website, but you can’t do this with WordPress out of the box. 

Ways to Add Code

There are three ways you can do this:

  1. Manually, which means you have to edit your themes header.PHP and footer.PHP files, which probably sounds quite complicated. It’s also a little risky and these can be overwritten if your theme gets an upgrade, and you do want to be upgrading your themes, so it’s probably not the best route to go. 
  2. You can also do it through your theme’s built-in headroom footer code feature if your theme has one.
  3. The third way is by using a plugin. I’m going to show you how to do it using a plugin, but it’s worth checking if your theme has the functionality built-in already, and you can do this by going to your ‘dashboard’, ‘login’, and then going down to ‘appearance’ and ‘customize’. Over on the left, if you can add header and footer scripts, it could be in there. That’s a good place to check before you upload a plugin. 

If you can’t do it through your Theme, what you will need to do is install a plugin. 

Installing Plugins

Go to plugins and click on ‘Add New’, and that will search for plugins. Search for header and footer script, and you should get a few options here, but the one I use on all of my websites is, ‘Insert headers and footers by WPBeginner’, and as you can see it’s got over a million active installations, so that’s a good sign that it’s a good plugin. 

Click on ‘Install Now’, click on ‘Activate’ and your plugin will be activated. 

Now to enter some code. All I need to do is go down to ‘Settings’, then down to ‘New menu item’, click on ‘insert headers and footers’, and now I have three options so I can add a script into my header, a script into the body. If a script tells you to add it after the body tag, you would put it into there, and the footer as well.

Google Analytics Example

Let’s take Google Analytics for example. If you wanted to install Google Analytics on your own site, then you just need to come to and register and set up your account. Once you’ve done that, come down to ‘Admin’ on the left, and then to ‘tracking info’, and then ‘tracking code’, and you’ll get a little bit of script (see video), which says, “Copy and paste this as the first item into your head of every webpage you want to track.” It must be first because this is Google Analytics and you want it to track everything that happens on your websites, you don’t want any other scripts interfering with it. The only script I would put before Google Analytics is a cookie script because cookies need to have priority over all the scripts, so someone can opt-out of being tracked for cookies. 

Copy and Paste

All I then need to do is copy the code, which I haven’t had to write, and don’t have to insert it into the head of every webpage myself, because this does that for me, so anything that’s in the header will show on every single webpage I have on my website. 

I click in the header code box and I can right-click to paste or ctrl+V and it will be added in. I don’t suggest you change anything in here, I’d leave everything as it is. The orange script at the top is a comment, which tells you what this particular script is. So if you had one for Pinterest, or you had one for Facebook pixel, they would all be in here and you could tell which one was which, and if you wanted to remove one you could easily. 

Finishing touches

When you’re finished, click on ‘Save’ to update it and save it to your website: Google Analytics are now active. The best thing about this plugin is that you can add as many scripts as you want, so next time you’re trying to set up Google Analytics, or integrate with Facebook or Pinterest you’ll be ready to go, and it will only be a 30-second job. 

Thank you so much for watching. It’s been really lovely to have you here, and I’ve got a whole playlist of WordPress tutorial videos. So be sure to go and check them out if you have a WordPress website. And don’t forget to like, and subscribe, and I will see you again soon.

Share the



Leave a Reply

Your email address will not be published.

Join the List

Signup to the Opal & Onyx newsletter for offers and a weekly dose of Website inspiration & help!