Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #1293811

    Hi,
    I want to remove all LayerSlider scripts and styles on mobile devices. My usual approach is:

    
    function custom_dequeue_script() {
       if( wp_is_mobile() ) {
              wp_dequeue_script( 'layerslider' );
    	  wp_deregister_script( 'layerslider' );
    	  wp_dequeue_script( 'layerslider-utils' );
    	  wp_deregister_script( 'layerslider-utils' );
    	  wp_dequeue_script( 'layerslider-transitions' );
    	  wp_deregister_script( 'layerslider-transitions' );
    	  wp_dequeue_script( 'ls-user-transitions' );
    	  wp_deregister_script( 'ls-user-transitions' );
              wp_dequeue_style( 'layerslider' );
    	  wp_deregister_style( 'layerslider' );
    	  wp_dequeue_style( 'layerslider-front' );
    	  wp_deregister_style( 'layerslider-front' );
    	  wp_dequeue_style( 'avia-module-slideshow-ls' );
    	  wp_deregister_style( 'avia-module-slideshow-ls' );
    	  wp_dequeue_script( 'avia-module-slideshow-ls' );
    	  wp_deregister_script( 'avia-module-slideshow-ls' );
    	  wp_dequeue_style( 'ls-user' );
    	  wp_deregister_style( 'ls-user' );
    	}
    }
    add_action( 'wp_enqueue_scripts', ' custom_dequeue_script', 100 );
    

    However, wp_is_mobile() doesn’t seem to be working in Enfold. How can I detect a mobile user and dequeue all those scripts?
    Many thanks

    • This topic was modified 3 years, 1 month ago by ivpeve.
    #1294152

    Hey,

    Thanks for contacting us!

    I believe that is the way to detect mobile on WP.
    I have just tested wp_is_mobile() function on my test site and it works.

    Please try using the code as following

    function custom_dequeue_script() {
       if( wp_is_mobile() ) {
              wp_dequeue_script( 'layerslider' );
    	  wp_deregister_script( 'layerslider' );
    	  wp_dequeue_script( 'layerslider-utils' );
    	  wp_deregister_script( 'layerslider-utils' );
    	  wp_dequeue_script( 'layerslider-transitions' );
    	  wp_deregister_script( 'layerslider-transitions' );
    	  wp_dequeue_script( 'ls-user-transitions' );
    	  wp_deregister_script( 'ls-user-transitions' );
              wp_dequeue_style( 'layerslider' );
    	  wp_deregister_style( 'layerslider' );
    	  wp_dequeue_style( 'layerslider-front' );
    	  wp_deregister_style( 'layerslider-front' );
    	  wp_dequeue_style( 'avia-module-slideshow-ls' );
    	  wp_deregister_style( 'avia-module-slideshow-ls' );
    	  wp_dequeue_script( 'avia-module-slideshow-ls' );
    	  wp_deregister_script( 'avia-module-slideshow-ls' );
    	  wp_dequeue_style( 'ls-user' );
    	  wp_deregister_style( 'ls-user' );
    	}
    }
    add_action( 'wp_print_scripts', ' custom_dequeue_script', 100 );

    Best regards,
    Yigit

    #1294193

    isn’t it possible to use the function layerslider_deactivation_scripts() { for that.
    and use that hook: do_action(‘layerslider_deactivated’);

    #1295365

    Thanks @Yigit – it worked now with a small modification. It seems I had left an empty space before the name of the function when calling it.

    #1295375

    Hi,

    Did you need additional help with this topic or shall we close?

    Best regards,
    Jordan Shannon

    #1295376

    Close it please. Thanks

    #1295459

    Hi,

    You are welcome! :)

    For your information, you can take a look at Enfold documentation here – https://kriesi.at/documentation/enfold/

    If you have any other questions or issues, feel free to start a new thread under Enfold sub forum and we will gladly try to help you :)

    Enjoy the rest of your day!

    Best regards,
    Yigit

Viewing 7 posts - 1 through 7 (of 7 total)
  • The topic ‘Detect mobile in PHP?’ is closed to new replies.