How to Hard-Code a UA String for the Google Analytics for WordPress Plugin

If you want to define a Google Analytics “UA String” while using Yoast Google Analytics plugin for WordPress.

Add the following to your theme’s functions.php file:

add_filter( 'option_Yoast_Google_Analytics', 'custom_ua_string_filter');

function custom_ua_string_filter($options = array()) {
	$options['uastring'] = 'UA-########-#';
	$options['manual_uastring'] = true;
	return $options;
}

For users of WordPress Multisite, this will allow you to pre-configure new blogs with the same UA string.

This entry was posted in Web Development, WordPress. Bookmark the permalink.