Search code examples
javascriptwordpressmobiletablet

disable enqueued Javascript on mobile in wordpress


I'm a beginner in wordpress, I'm trying to add skrollr to my wordpress theme, and everything is working fine on the desktop but not on the ipad or iphone.. here's my enqueued code:`function skrollr_scripts() {

wp_enqueue_script( 'skrollr_js', get_template_directory_uri() . '/js/skrollr.min.js', array(), '1.0.0', true );
wp_enqueue_script( 'myscript_js', get_template_directory_uri().'/js/myscript.js', array(), '1.0.0', true);

}` I was wondering if there's any way I can disable the javascript files ONLY on mobile devices?


Solution

  • Please replace the code

    wp_enqueue_script( 'skrollr_js', get_template_directory_uri() . '/js/skrollr.min.js', array(), '1.0.0', true );
    wp_enqueue_script( 'myscript_js', get_template_directory_uri().'/js/myscript.js', array(), '1.0.0', true);
    

    with

    if ( !wp_is_mobile() ) {
        wp_enqueue_script( 'skrollr_js', get_template_directory_uri() . '/js/skrollr.min.js', array(), '1.0.0', true );
        wp_enqueue_script( 'myscript_js', get_template_directory_uri().'/js/myscript.js', array(), '1.0.0', true);
    }
    

    This will solve your problem.