如何阻止脚本在wordpress中的特定页面上运行?

时间:2013-12-09 07:57:09

标签: wordpress-plugin wordpress

以下脚本适用于MU插件,可在网站的所有页面上加载跟踪javascript。如何提供条件,以便脚本不会加载到特定的wordpress页面上?

define('GAUGES_ID', 'xxxxxxxxxxxxxxx');
function zk_gauges() {


  ?>
  <script type="text/javascript">
    (function() {
      var t   = document.createElement('script');
      t.type  = 'text/javascript';
      t.async = true;
      t.id    = 'gauges-tracker';
      t.setAttribute('data-site-id', '<?php echo esc_js(GAUGES_ID) ?>');
      t.src = '//secure.gaug.es/track.js';
      var s = document.getElementsByTagName('script')[0];
      s.parentNode.insertBefore(t, s);
    })();
  </script>
  <?php

}

if (!is_admin()) {
  add_action('wp_footer', 'zk_gauges', 99);

我试过(!is_admin()) || !is_page(pid),其中pid是页面ID。但它没有帮助。

1 个答案:

答案 0 :(得分:1)

(!is_admin()) && !is_page(pid))

使用AND代替OR。当您使用OR时,如果!is_admin()评估为true(不在仪表板上而不是ajax),则不会评估条件!is_page(pid)