If you want to add Google Analytics to your WordPress site without using a plugin, you can use this snippet:
<?php
add_action( 'wp_head', 'wpsnippets_google_analytics_scripts' );
function wpsnippets_google_analytics_scripts() {
// Add your Google analytics scripts here, like so:
?><script>...</script><?php
}
If you need to add code after the <body>
opening tag as well, you can use the snippet below:
<?php
add_action( 'wp_body_open', 'wpsnippets_google_analytics_body' );
function wpsnippets_google_analytics_body() {
// Add your Google analytics scripts here, like so:
?><script>...</script><?php
}