我正在嘗試阻止腳本在我的 WordPress 網(wǎng)站上以 HTML 形式加載。 在我的 HTML 檔案中,我可以看到這兩個(gè)腳本:
<script type="0f1a6d7ca503db410c0d10c4-text/javascript" src='https://www.[-----------].se/wp-content/plugins/theme -my-login/資產(chǎn)/腳本/theme-my-login.min.js?ver=7.1.2' id='theme-my-login-js'></script>
<script type="0f1a6d7ca503db410c0d10c4-text/javascript" src='https://www.phpcnc.com [------------].se/wp-content /themes/guru/framework/js/public/jquery.smartresize.js?ver=5.5.2' id='jquery-smartresize-js '></script>
#在public_html/wp-content/themes/guru/framework/register_public.php
中,我可以註解掉第二個(gè)腳本,並透過在上面的php 中設(shè)置/* */ 來防止其載入到HTML檔案:
/* wp_enqueue_script('jquery-smartresize', $template_uri.'/js/public/jquery.smartresize.js', array(), false, true); */
第一個(gè)腳本來自我想在某個(gè)頁面上使用的插件,所以我不想停用該插件。我將在 php 檔案中建立一個(gè) IF 語句,以根據(jù)頁面 URL 排除/包含插件腳本載入到 HTML 中。
我的問題是我找不到將第一個(gè)腳本載入到 HTML 的 php 檔案,就像我為第二個(gè)腳本找到的那樣。在 public_html 中透過 ssh 搜尋時(shí),我沒有發(fā)現(xiàn)任何有趣的內(nèi)容或獲得很多點(diǎn)擊。我可以添加過濾器廣告嗎?過濾器的程式碼是怎樣的?我想最好阻止 wp_enqueue_script 執(zhí)行,而不是讓 wp_enqueue_script 然後添加過濾器。
其實(shí)我只用過
if ( isset( $_SERVER['REQUEST_URI'] ) && strpos( $_SERVER['REQUEST_URI'], 'the/page/that/uses/the/scripts' ) === false ) {wp_dequeue_script( 'theme-my-login' ); }
我沒有呼叫函數(shù) SO_21097900...這不起作用...我不知道該函數(shù)該放在哪裡。如果我將該函數(shù)放在同一個(gè) php 檔案中,那麼我的網(wǎng)站就會(huì)崩潰。
是的,您可以在不需要的地方將腳本出列
function SO_21097900() { wp_dequeue_script( 'theme-my-login' ); wp_dequeue_script( 'jquery-smartresize' ); } if ( isset( $_SERVER['REQUEST_URI'] ) && strpos( $_SERVER['REQUEST_URI'], 'the/page/that/uses/the/scripts' ) === false ) { add_action( 'wp_enqueue_scrips', 'SO_21097900', 100 ); }