Simple snippet to add script to your WordPress template footer without having to add it into your footer.php. You can use this to append Google Analytic Code by using add_action function and append your script to wp_footer. It's a cleaner solution so your html file always separate from Javascript.
PHP
Open functions.php and append the following. Of course, change $account to your google analytic account.
add_action('wp_footer', 'ga'); function ga() { $account = 'UA-1234567-8'; // your account id should look something like this. $code = "<script type=\"text/javascript\"> var _gaq = _gaq || []; _gaq.push(['_setAccount', '$account']); _gaq.push(['_trackPageview']); (function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })(); </script>"; echo $code; }
Comments will be moderated and
rel="nofollow"
will be added to all links. You can wrap your coding with[code][/code]
to make use of built-in syntax highlighter.Why do you think it's more difficult to edit footer.php and to paste a clean code from googleAnalytics? Stupid way!
regards,
Jenna
Cheers!
Jenna & Andhie
http://gkfy.com