Add Code to Header Using WordPress Functions.php

When you want to add analytics or any other code to your WordPress header, the easiest way to do this is to add a line of code to your functions.php. This line of code should be placed inside your functions php file preferably of a child theme so it doesn’t get overwritten by an update.  If you change themes though you will need to add this code again.

Using functions.php to add Google analytics code to header of WordPress

This is my favorite use of this code. It’s the lightest implementation. Sure you can use a plugin to do the same thing. But let Google do the heavy lifting.  First you need to grab your code by using an existing or setting up an analytics account at

tracking code location in google analytics

Location of your tracking code in Google analytics

You can add this code in the wordpress admin panel under Appearance>editor>functions.php. But be warned it’s better to do this with direct access to the server using ftp or shell access. If you don’t insert the code correctly the site will go down. So make sure you have access to the functions.php directly through your server.

Here is the code:

Do you have any other methods you prefer to insert code into the header of your website?

If you want some help doing this please contact me.


About John Schuster

My passion is helping business owners and entrepreneurs use the internet to find customers and make money. This includes email marketing, social media marketing, content marketing, PPC, and SEO. I work hard to be the best, and with that bring an arsenal of tools to help you business. Call me (206) 235-4131 Please feel free to use me as a resource and contact me with questions.
This entry was posted in Web Development. Bookmark the permalink.

Leave a reply