2016-10-09 31 views
0

我在放網頁 有錯誤此代碼插入插件Ajax的命中計數器,禁用腳本WordPress的

<script type="text/javascript"><![CDATA[function ahc_getXmlHttp(){var e;try{e=new ActiveXObject("Msxml2.XMLHTTP")}catch(t){try{e=new ActiveXObject("Microsoft.XMLHTTP")}catch(n){e=false}}if(!e&&typeof XMLHttpRequest!="undefined"){e=new XMLHttpRequest}return e};var ahc_xmlhttp=ahc_getXmlHttp();ahc_xmlhttp.open("GET", "https://example.org/wp-content/plugins/ajax-hits-counte5r/increment-hits.rapid.php?post_id=547754&t="+(parseInt(new Date().getTime()))+"&r="+(parseInt(Math.random()*100000)));ahc_xmlhttp.send(null);]]></script> 

AMP驗證寫道:標籤「腳本」是不允許的,除了以特定形式。

這裏插入腳本函數:

public function appendScript($content) 
{ 
    global $post; 

    if(is_single() || is_page()) 
    { 
     if($this->getOption('use_rapid_incrementer')==1)   // use rapid incrementer 
     { 
      $incrementer_url = plugin_dir_url(__FILE__).'increment-hits.rapid.php?post_id='.$post->ID.'&t='; 
     } 
     else            // use simple incrementer 
     { 
      $incrementer_url = admin_url('admin-ajax.php').'?action='.$this->plugin_alias.'-increment&post_id='.$post->ID.'&t='; 
     } 

     $content .= 
      '<script type="text/javascript">'. 
       'function ahc_getXmlHttp(){var e;try{e=new ActiveXObject("Msxml2.XMLHTTP")}catch(t){try{e=new ActiveXObject("Microsoft.XMLHTTP")}catch(n){e=false}}if(!e&&typeof XMLHttpRequest!="undefined"){e=new XMLHttpRequest}return e};'. 
       'var ahc_xmlhttp=ahc_getXmlHttp();'. 
       'ahc_xmlhttp.open('. 
        '"GET", "'.$incrementer_url.'"+(parseInt(new Date().getTime()))+"&r="+(parseInt(Math.random()*100000))'. 
        ');'. 
       'ahc_xmlhttp.send(null);'. 
      '</script>'; 
    } 

    return $content; 
} 

如何從AMP頁面中刪除此腳本?

回答

1

這是一個解決方案。

  1. 可以使用WordPress插件插入腳本「我的自定義功能 」 https://wordpress.org/plugins/my-custom-functions/

  2. 然後轉到AMPforWP插件的插件管理器設置(假設 已安裝ampforwp.com的AMPforWP插件)。

  3. 在那裏您可以禁用我的自定義功能插件在 AMP頁面上執行。

AMPforWP的插件管理器頁面截圖:https://i.imgur.com/JIypHQsg.jpg。它爲我工作,因爲我試圖禁用AMP頁面上的腳本,該頁面被我的自定義函數插件插入。