How to add google analytics code in wordpress using functions.php

We use google analytics code on website so that we can see the traffic and other information of website. For this we generate google analytics code add the script on header.php file or footer.php file. But we can also add analytics code in functions.php file which is available inside the wordpress theme.

So just you need to create a function and use hook. To add in footer use “wp_footer” hook and if you want to add in header use “wp_head” hook.

But I am adding currently in footer for this just use this code:

Enjoy the code!

Leave a Reply