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 Answer
Reset to default 1It 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. :)
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