1,488   WordPress

在wordpress中添加统计代码

参考这里的方法

http://blog.sina.com.cn/s/blog_9bf4617f01011aul.html

 

插件会拖慢网站,所以采用手动添加代码,又不想直接修改footer.php,最终采用下面的方法

在主题模板模板的functions.php 中添加以下代码,

function add_googleanalytics() { ?>

/*这里添加统计的JS代码,谷歌和百度的统计代码*/

 

<script>

(function(i,s,o,g,r,a,m){i[‘GoogleAnalyticsObject’]=r;i[r]=i[r]||function(){

(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),

m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)

})(window,document,’script’,’//www.google-analytics.com/analytics.js’,’ga’);

 

ga(‘create’, ‘UA-52093811-1’, ‘luckybird.me’);

ga(‘send’, ‘pageview’);

 

</script>

 

<script type=”text/javascript”>

var _bdhmProtocol = ((“https:” == document.location.protocol) ? ” https://” : ” http://”);

document.write(unescape(“%3Cscript src='” + _bdhmProtocol + “hm.baidu.com/h.js%3F88056e92dbae278a1a6511813bafa1a1′ type=’text/javascript’%3E%3C/script%3E”));

</script>

 

<?php }

add_action(‘wp_footer’, ‘add_googleanalytics’);

 

 




Leave a Reply

Your email address will not be published. Required fields are marked *