WP_IS_MOBILE出队不工作

时间:2020-12-26 作者:Rasam Server

根据本主题:Dequeue Scripts and Style for Mobile not working?

我用了最后一个答案Slider revolution 插件,但它不起作用:

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\' );
}
}
我只想禁用这两个js文件:rbtools。最小js和rs6。min.js来自移动加载,以在灯塔中获得更好的排名。

这两个js文件从此文件加载:/wp-content/plugins/revslider/public/assets/revslider-front.class.php :本部分:

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

1 个回复
SO网友:deronimo

看起来您正在使用脚本;src“;而不是剧本;句柄;。您是否尝试过:

add_action( \'wp_enqueue_scripts\', \'remove_plugin_scripts\', PHP_INT_MAX );
函数remove\\u plugin\\u scripts(){if(wp\\u is\\u mobile()){

// Remove script file.
wp_dequeue_script( \'tp-tools\' );
wp_deregister_script( \'tp-tools\' );

wp_dequeue_script( \'revmin\' );
wp_deregister_script( \'revmin\' );
}
}