Tagged: Layer Slider, mobile, php
-
AuthorPosts
-
April 12, 2021 at 12:49 am #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, 7 months ago by ivpeve.
April 13, 2021 at 3:56 pm #1294152Hey,
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,
YigitApril 13, 2021 at 5:19 pm #1294193isn’t it possible to use the function layerslider_deactivation_scripts() { for that.
and use that hook:do_action(‘layerslider_deactivated’);
April 19, 2021 at 11:19 pm #1295365Thanks @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.
April 20, 2021 at 12:28 am #1295375Hi,
Did you need additional help with this topic or shall we close?
Best regards,
Jordan ShannonApril 20, 2021 at 12:31 am #1295376Close it please. Thanks
April 20, 2021 at 9:16 am #1295459Hi,
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 -
AuthorPosts
- The topic ‘Detect mobile in PHP?’ is closed to new replies.