You will require a child theme to be installed or you can add this as a plugin using our plugin boilerplate template.
// Add Google Analytics code to <head>
function my_google_analytics() { ?>
// Paste your Google Analytics code below this line
// Paste your Google Analytics code above this line
<?php }
add_action('wp_head','my_google_analytics', 10);
Or you can add the code to the footer of your website by using the following snippet.
// Add Google Analytics code in the footer
function my_google_analytics() { ?>
// Paste your Google Analytics code below this line
// Paste your Google Analytics code above this line
<?php }
add_action('wp_footer', 'my_google_analytics');
– LAST TESTED DECEMBER 9, 2019
Code not working? Let us know in the comments below.