最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - wp_dequeue_script for a Plugin

programmeradmin0浏览0评论

I am trying to remove a line of script in the footer of my page that a plugin is inserting on pages that I am not using the plugin at, homepage for example. I am using the below code for some reason it will still display the script. Any suggestions?

The line I need removed: <script type='text/javascript' src='.min.js?ver=2.6.11' id='jet-vue-js'></script>

The code in my functions.php

function review_enqueue() {
    if (is_front_page()) {
       wp_dequeue_script('jet-vue-js');
    }
}
add_action('wp_dequeue_scripts', 'review_enqueue');

I am trying to remove a line of script in the footer of my page that a plugin is inserting on pages that I am not using the plugin at, homepage for example. I am using the below code for some reason it will still display the script. Any suggestions?

The line I need removed: <script type='text/javascript' src='https://domain/wp-content/plugins/jet-reviews/assets/js/lib/vue.min.js?ver=2.6.11' id='jet-vue-js'></script>

The code in my functions.php

function review_enqueue() {
    if (is_front_page()) {
       wp_dequeue_script('jet-vue-js');
    }
}
add_action('wp_dequeue_scripts', 'review_enqueue');
Share Improve this question asked Jan 18, 2021 at 23:54 user200552user200552 11 bronze badge 2
  • 1 There is no wp_dequeue_scripts action, have you contacted jet reviews support? 3rd party plugin dev support is offtopic here – Tom J Nowell Commented Jan 19, 2021 at 0:39
  • You're applying this incorrectly: developer.wordpress/reference/functions/wp_dequeue_script You will then also need to make sure this executes after the plugin has already registered the script. – Tony Djukic Commented Jan 19, 2021 at 3:01
Add a comment  | 

1 Answer 1

Reset to default 1

It still displays the script because you are using the wrong hook (and it doesn't exist) — wp_dequeue_scripts, and secondly, if the script is indeed enqueued via wp_enqueue_script(), then the generated id (used in the <script> tag) is in the form of <script handle>-js (i.e. suffixed with a -js) where <script handle> is the first parameter for wp_enqueue_script().

Therefore in your case, the script handle is just jet-vue without the -js, and try dequeuing the script via the wp_print_scripts hook instead.

function review_enqueue() {
        if ( is_front_page() ) {
             wp_dequeue_script( 'jet-vue' );
        }
}
add_action( 'wp_print_scripts', 'review_enqueue' );

If that doesn't work, you can try using a lower priority (i.e. a greater number) as the 3rd parameter for add_action(). E.g.

add_action( 'wp_print_scripts', 'review_enqueue', 20 );

And if that still doesn't work, then try contacting the plugin support and ask them for the proper way to dequeue their scripts. :)

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论