How to Insert Google Analytics

I like to use Google Analytics, but the boring stuff is that when you switch themes, you’ll have to re-insert the code in the new theme. To avoid it, let’s use the power of WordPress hook to insert our analytics code without editing theme files.

Just insert the following code into your functions.php file, and you’re done. Don’t forget to paste your Google Analytics code on line 5.

<?php
add_action('wp_footer', 'ga');

function ga() { ?>
    // Paste your Google Analytics code here
<?php } ?>

Tags: , ,

Related posts

One Comments

  • Yeah, that guide explains everything.

    You can always have a separate “footer.htm” or “footer.php” and insert the code into just that.
    Saves you the time from having to insert it into every single page.

    [Reply]

  • Join the discussion