如何解决使用wp_is_mobile为移动设备禁用wordpress插件
我正尝试使用 wp_is_mobile 功能-https://developer.wordpress.org/reference/functions/wp_is_mobile/
为移动设备禁用Navgoco Menu插件的CSS和JS文件。<?php if ( wp_is_mobile() ) : ?>
/* Display and echo mobile specific stuff here */
<?php else : ?>
/* Display and echo desktop stuff here */
<?php endif; ?>
但是无法从此代码中正确删除脚本和样式:
function scripts_styles() {
$options = get_option( 'navgoco_settings' );
wp_register_script ( 'navgocojs',plugins_url( '/js/jquery.navgoco.js',__FILE__ ),array( 'jquery' ),'0.2.1',false );
wp_register_script ( 'navgococookie',plugins_url( '/js/jquery.cookie.min.js','1.4.1',false );
wp_register_style ( 'navgococss',plugins_url( '/css/navgoco.css','','all' );
wp_register_script ( 'navgoco-init',plugins_url( '/js/navgoco-init.js',array( 'navgocojs' ),'1.0.0',false );
// Add new plugin options defaults here,set them to blank,this will avoid PHP notices of undefined,if new options are introduced to the plugin and are not saved or udated then the setting will be defined.
$options_default = array(
'ng_menu_save' => '','ng_menu_disable_style' => '','ng_menu_selection' => '','ng_menu_accordion' => '','ng_menu_html_carat' => '','ng_slide_easing' => '','ng_slide_duration' => '',);
$options = wp_parse_args( $options,$options_default );
wp_enqueue_script( 'navgocojs' );
if( (bool) $options['ng_menu_save'] == true ) {
wp_enqueue_script( 'navgococookie' );
}
if( (bool) $options['ng_menu_disable_style'] == false ) {
wp_enqueue_style( 'navgococss' );
wp_enqueue_style( 'fontawesome' );
}
$data = array (
'ng_navgo' => array(
'ng_menu_selection' => esc_html($options['ng_menu_selection']),'ng_menu_accordion' => (bool)$options['ng_menu_accordion'],'ng_menu_html_carat' => $options['ng_menu_html_carat'],'ng_slide_easing' => esc_html($options['ng_slide_easing']),'ng_slide_duration' => (int)$options['ng_slide_duration'],'ng_menu_save' => (bool)$options['ng_menu_save'],),);
//add filter
$data = apply_filters( 'ng_navgoco_navgocoVars',$data );
// Pass PHP variables to jQuery script
wp_localize_script( 'navgoco-init','navgocoVars',$data );
wp_enqueue_script( 'navgoco-init' );
}
是否可以在此处实现wp_is_mobile?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。