According to this topic: Dequeue Scripts and Style for Mobile not working?
I used the last answer but for Slider revolution plugin and it does not work:
This is my function in functions.php:
add_action( 'wp_enqueue_scripts', 'remove_plugin_scripts', PHP_INT_MAX );
function remove_plugin_scripts() {
if ( wp_is_mobile() ) {
// Remove script file.
wp_dequeue_script( 'rbtools.min.js' );
wp_deregister_script( 'rbtools.min.js' );
wp_dequeue_script( 'rs6.min.js' );
wp_deregister_script( 'rs6.min.js' );
}
}
I just want to disable this two js files: rbtools.min.js and rs6.min.js from mobile loading for better rank in lighthouse.
this two js files loads from this file: /wp-content/plugins/revslider/public/assets/revslider-front.class.php : this part:
/**
* dequeue tp-tools to make sure that always the latest is loaded
**/
global $wp_scripts;
if(version_compare($func->get_val($wp_scripts, array('registered', 'tp-tools', 'ver'), '1.0'), RS_TP_TOOLS, '<')){
wp_deregister_script('tp-tools');
wp_dequeue_script('tp-tools');
}
wp_enqueue_script('tp-tools', RS_PLUGIN_URL . 'public/assets/js/rbtools.min.js', $waitfor, RS_TP_TOOLS, $inc_footer);
if(!file_exists(RS_PLUGIN_PATH.'public/assets/js/rs6.min.js')){
wp_enqueue_script('revmin', RS_PLUGIN_URL . 'public/assets/js/dev/rs6.main.js', 'tp-tools', $rs_ver, $inc_footer);
//if on, load all libraries instead of dynamically loading them
wp_enqueue_script('revmin-actions', RS_PLUGIN_URL . 'public/assets/js/dev/rs6.actions.js', 'tp-tools', $rs_ver, $inc_footer);
wp_enqueue_script('revmin-carousel', RS_PLUGIN_URL . 'public/assets/js/dev/rs6.carousel.js', 'tp-tools', $rs_ver, $inc_footer);
wp_enqueue_script('revmin-layeranimation', RS_PLUGIN_URL . 'public/assets/js/dev/rs6.layeranimation.js', 'tp-tools', $rs_ver, $inc_footer);
wp_enqueue_script('revmin-navigation', RS_PLUGIN_URL . 'public/assets/js/dev/rs6.navigation.js', 'tp-tools', $rs_ver, $inc_footer);
wp_enqueue_script('revmin-panzoom', RS_PLUGIN_URL . 'public/assets/js/dev/rs6.panzoom.js', 'tp-tools', $rs_ver, $inc_footer);
wp_enqueue_script('revmin-parallax', RS_PLUGIN_URL . 'public/assets/js/dev/rs6.parallax.js', 'tp-tools', $rs_ver, $inc_footer);
wp_enqueue_script('revmin-slideanims', RS_PLUGIN_URL . 'public/assets/js/dev/rs6.slideanims.js', 'tp-tools', $rs_ver, $inc_footer);
wp_enqueue_script('revmin-video', RS_PLUGIN_URL . 'public/assets/js/dev/rs6.video.js', 'tp-tools', $rs_ver, $inc_footer);
}else{
wp_enqueue_script('revmin', RS_PLUGIN_URL . 'public/assets/js/rs6.min.js', 'tp-tools', $rs_ver, $inc_footer);
}
add_action('wp_head', array('RevSliderFront', 'add_meta_generator'));
add_action('wp_head', array('RevSliderFront', 'js_set_start_size'), 99);
add_action('admin_head', array('RevSliderFront', 'js_set_start_size'), 99);
add_action('wp_footer', array('RevSliderFront', 'load_icon_fonts'));
add_action('wp_footer', array('RevSliderFront', 'load_google_fonts'));
//Async JS Loading
if($func->_truefalse($func->get_val($global, array('script', 'defer'), false)) === true){
add_filter('clean_url', array('RevSliderFront', 'add_defer_forscript'), 11, 1);
}
add_action('wp_before_admin_bar_render', array('RevSliderFront', 'add_admin_menu_nodes'));
add_action('wp_footer', array('RevSliderFront', 'add_admin_bar'), 99);
}
According to this topic: Dequeue Scripts and Style for Mobile not working?
I used the last answer but for Slider revolution plugin and it does not work:
This is my function in functions.php:
add_action( 'wp_enqueue_scripts', 'remove_plugin_scripts', PHP_INT_MAX );
function remove_plugin_scripts() {
if ( wp_is_mobile() ) {
// Remove script file.
wp_dequeue_script( 'rbtools.min.js' );
wp_deregister_script( 'rbtools.min.js' );
wp_dequeue_script( 'rs6.min.js' );
wp_deregister_script( 'rs6.min.js' );
}
}
I just want to disable this two js files: rbtools.min.js and rs6.min.js from mobile loading for better rank in lighthouse.
this two js files loads from this file: /wp-content/plugins/revslider/public/assets/revslider-front.class.php : this part:
/**
* dequeue tp-tools to make sure that always the latest is loaded
**/
global $wp_scripts;
if(version_compare($func->get_val($wp_scripts, array('registered', 'tp-tools', 'ver'), '1.0'), RS_TP_TOOLS, '<')){
wp_deregister_script('tp-tools');
wp_dequeue_script('tp-tools');
}
wp_enqueue_script('tp-tools', RS_PLUGIN_URL . 'public/assets/js/rbtools.min.js', $waitfor, RS_TP_TOOLS, $inc_footer);
if(!file_exists(RS_PLUGIN_PATH.'public/assets/js/rs6.min.js')){
wp_enqueue_script('revmin', RS_PLUGIN_URL . 'public/assets/js/dev/rs6.main.js', 'tp-tools', $rs_ver, $inc_footer);
//if on, load all libraries instead of dynamically loading them
wp_enqueue_script('revmin-actions', RS_PLUGIN_URL . 'public/assets/js/dev/rs6.actions.js', 'tp-tools', $rs_ver, $inc_footer);
wp_enqueue_script('revmin-carousel', RS_PLUGIN_URL . 'public/assets/js/dev/rs6.carousel.js', 'tp-tools', $rs_ver, $inc_footer);
wp_enqueue_script('revmin-layeranimation', RS_PLUGIN_URL . 'public/assets/js/dev/rs6.layeranimation.js', 'tp-tools', $rs_ver, $inc_footer);
wp_enqueue_script('revmin-navigation', RS_PLUGIN_URL . 'public/assets/js/dev/rs6.navigation.js', 'tp-tools', $rs_ver, $inc_footer);
wp_enqueue_script('revmin-panzoom', RS_PLUGIN_URL . 'public/assets/js/dev/rs6.panzoom.js', 'tp-tools', $rs_ver, $inc_footer);
wp_enqueue_script('revmin-parallax', RS_PLUGIN_URL . 'public/assets/js/dev/rs6.parallax.js', 'tp-tools', $rs_ver, $inc_footer);
wp_enqueue_script('revmin-slideanims', RS_PLUGIN_URL . 'public/assets/js/dev/rs6.slideanims.js', 'tp-tools', $rs_ver, $inc_footer);
wp_enqueue_script('revmin-video', RS_PLUGIN_URL . 'public/assets/js/dev/rs6.video.js', 'tp-tools', $rs_ver, $inc_footer);
}else{
wp_enqueue_script('revmin', RS_PLUGIN_URL . 'public/assets/js/rs6.min.js', 'tp-tools', $rs_ver, $inc_footer);
}
add_action('wp_head', array('RevSliderFront', 'add_meta_generator'));
add_action('wp_head', array('RevSliderFront', 'js_set_start_size'), 99);
add_action('admin_head', array('RevSliderFront', 'js_set_start_size'), 99);
add_action('wp_footer', array('RevSliderFront', 'load_icon_fonts'));
add_action('wp_footer', array('RevSliderFront', 'load_google_fonts'));
//Async JS Loading
if($func->_truefalse($func->get_val($global, array('script', 'defer'), false)) === true){
add_filter('clean_url', array('RevSliderFront', 'add_defer_forscript'), 11, 1);
}
add_action('wp_before_admin_bar_render', array('RevSliderFront', 'add_admin_menu_nodes'));
add_action('wp_footer', array('RevSliderFront', 'add_admin_bar'), 99);
}
Share Improve this question edited Dec 27, 2020 at 6:08 Rasam Server asked Dec 26, 2020 at 8:41 Rasam ServerRasam Server 112 bronze badges 3- Can you show us the register and enqueue lines from revslider-front? Are they definitely only enqueued with is_mobile() or do they use slightly different logic? – Rup Commented Dec 26, 2020 at 13:04
- I'd guess the problem is that you're using the wrong strings for wp_dequeue_script - it should be the $handle argument it was registered with, not the name of the script - but we'd need to see the register lines to know for sure. – Rup Commented Dec 26, 2020 at 13:14
- I added part of enqueue lines. thank you for help – Rasam Server Commented Dec 27, 2020 at 6:10
1 Answer
Reset to default 1It looks like you are using the script "src" rather than the script "handle". Have you tried:
add_action( 'wp_enqueue_scripts', 'remove_plugin_scripts', PHP_INT_MAX );
function remove_plugin_scripts() { if ( wp_is_mobile() ) {
// Remove script file.
wp_dequeue_script( 'tp-tools' );
wp_deregister_script( 'tp-tools' );
wp_dequeue_script( 'revmin' );
wp_deregister_script( 'revmin' );
}
}