停止请求在 HTML 文件中加载脚本
P粉154798196
P粉154798196 2024-04-01 00:05:44
0
2
358

我正在尝试阻止脚本在我的 WordPress 网站上以 HTML 形式加载。 在我的 HTML 文件中,我可以看到这两个脚本:

<script type="0f1a6d7ca503db410c0d10c4-text/javascript" src='https://www.[-----------].se/wp-content/plugins/theme-my-login/资产/脚本/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 中,我可以注释掉第二个脚本,并通过在上面的 php 中设置 /* */ 来防止其加载到 HTML文件:

/* wp_enqueue_script('jquery-smartresize', $template_uri.'/js/public/jquery.smartresize.js', array(), false, true); */

第一个脚本来自我想在某个页面上使用的插件,所以我不想停用该插件。我将在 php 文件中构建一个 IF 语句,以根据页面 URL 排除/包含插件脚本加载到 HTML 中。

我的问题是我找不到将第一个脚本加载到 HTML 的 php 文件,就像我为第二个脚本找到的那样。在 public_html 中通过 ssh 搜索时,我没有发现任何有趣的内容或获得很多点击。我可以添加过滤器广告吗?过滤器的代码是怎样的?我想最好阻止 wp_enqueue_script 执行,而不是让 wp_enqueue_script 然后添加过滤器。

P粉154798196
P粉154798196

全部回复(2)
P粉691958181

其实我只用过

if ( isset( $_SERVER['REQUEST_URI'] ) &&
strpos( $_SERVER['REQUEST_URI'], 'the/page/that/uses/the/scripts' ) === false ) 
{wp_dequeue_script( 'theme-my-login' );
}

我没有调用函数 SO_21097900...这不起作用...我不知道该函数该放在哪里。如果我将该函数放在同一个 php 文件中,那么我的网站就会崩溃。

P粉734486718

是的,您可以在不需要的地方将脚本出列

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 );
}
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!