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 http://google.com/analytics.

Google analytics tracking code

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.