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:
- 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.
- You can also do it through your theme’s built-in headroom footer code feature if your theme has one.
- 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.
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
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.
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.