我需要在IF条件下编写代码,但我坚持该怎么做。
我有一个多站点WordPress网站(带有域映射),并且我尝试添加google分析单个网址跟踪器更改(如果url更改的话)。
例如,如果domain是“ mydomain.com”,我会编写代码以注入GA代码
<?php if (bloginfo('mydomain.com')) { ?>
(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-7567xxxx-x', 'auto');
ga('send', 'pageview');
<?php } ?>
但是结果并不是我所期望的,如果域更改后我需要更改结果,那么任何人都可以帮助我。
好的,我发现您的代码中几乎没有错误:$ siteURL
<?php
// Set your domain
$siteURL = "http://www.example.com/";
// Match with the get_site_url function
if($siteURL == get_site_url()) { ?>
<!-- your JS/HTML goes code here -->
<?php } ?>
非常感谢Flux的帮助
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句