Install Google Analytics in WordPress

If you want to install your WordPress script so that it works regardless of the theme you install you will need to  paste your code into the general-template.php file in the wp-includes folder.  Here are the steps

1.  In your WordPress installation go into wp-includes

1

2. Edit general-template.php2

3. Edit function get_footer() on line 53

at the bottom of the function (around line 68)  before the closing “}” put a  ” ?>” . . . At that point paste in your Google analytics script (This is the script that you would get after registering your site at Google.com/analytics.  Paste The code then put “<?php” .  Save your file – Delete the cache of WordPress and everything should be working.

3What we’ve done is install the Google Analytics script into the get-footer function.  That way anytime that function is called (i.e. the end of the wordpress template action) the analytics script will be drawn.  That will ensure that whatever template you are using the script will work – eliminating the need to put the script into any actual template code.

*This will only work if the template you are using calls the get-footer function.

** IF YOU UPGRADE WORDPRESS YOUR CODE WILL DISAPPEAR AND YOU WILL NEED TO REPEAT THIS PROCESS.  When you do an upgrade the WordPress core files are replaced with the newest version of the CMS – this will remove any custom code you made.

 

You may also like...