首页  >  问答  >  正文

停止请求在 HTML 文件中加载脚本

我正在尝试阻止脚本在我的 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粉154798196P粉154798196175 天前341

全部回复(2)我来回复

  • P粉691958181

    P粉6919581812024-04-01 12:36:37

    其实我只用过

    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 文件中,那么我的网站就会崩溃。

    回复
    0
  • P粉734486718

    P粉7344867182024-04-01 09:16:46

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

    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 );
    }
    

    回复
    0
  • 取消回复