• I was trying to remove plugin`s CSS and JS files for mobile devices, with wp_is_mobile function – https://developer.ww.wp.xz.cn/reference/functions/wp_is_mobile/

    <?php if ( wp_is_mobile() ) : ?>
        /* Display and echo mobile specific stuff here */
    <?php else : ?>
        /* Display and echo desktop stuff here */
    <?php endif; ?>

    but failed to remove scripts and style correctly from this code:

    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',  __FILE__ ), array( 'jquery' ), '1.4.1', false );
          wp_register_style ( 'navgococss' , plugins_url( '/css/navgoco.css',  __FILE__ ), '' , '0.2.1', 'all' );
          wp_register_script ( 'navgoco-init' , plugins_url( '/js/navgoco-init.js',  __FILE__ ), 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' );
        
        }

    Is it possible to implement wp_is_mobile here?

The topic ‘disable plugin for mobile devices using wp_is_mobile’ is closed to new replies.