Close #680 - Move Google Analytics to scripts.php

This commit is contained in:
Ben Word
2013-02-10 19:35:43 -06:00
parent 8ba19a0155
commit 1a7017c1a7
3 changed files with 14 additions and 12 deletions

View File

@@ -27,8 +27,6 @@ The `content-single.php` template is included by single post templates in the th
`footer.php` includes the Footer sidebar area and displays the site copyright information.
Also included is the [asynchronous Google Analytics snippet](http://mathiasbynens.be/notes/async-analytics-snippet) from HTML5 Boilerplate if an ID is defined in `config.php`.
### head.php
`head.php` includes everything in the `<head>`.

View File

@@ -67,3 +67,16 @@ function roots_jquery_local_fallback($src, $handle) {
if (!is_admin()) {
add_filter('script_loader_src', 'roots_jquery_local_fallback', 10, 2);
}
function roots_google_analytics() { ?>
<script>
var _gaq=[['_setAccount','<?php echo GOOGLE_ANALYTICS_ID; ?>'],['_trackPageview']];
(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];
g.src=('https:'==location.protocol?'//ssl':'//www')+'.google-analytics.com/ga.js';
s.parentNode.insertBefore(g,s)}(document,'script'));
</script>
<?php }
if (GOOGLE_ANALYTICS_ID) {
add_action('wp_footer', 'roots_google_analytics', 20);
}

View File

@@ -5,13 +5,4 @@
</div>
</footer>
<?php if (GOOGLE_ANALYTICS_ID) : ?>
<script>
var _gaq=[['_setAccount','<?php echo GOOGLE_ANALYTICS_ID; ?>'],['_trackPageview']];
(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];
g.src=('https:'==location.protocol?'//ssl':'//www')+'.google-analytics.com/ga.js';
s.parentNode.insertBefore(g,s)}(document,'script'));
</script>
<?php endif; ?>
<?php wp_footer(); ?>
<?php wp_footer(); ?>