Disable jquery.js for mobile devices only

Im using theme x, Icon. I would like to disable wp-includes/js/jquery/jquery.js for mobile phones only, not tablets. I am trying to disable this file from all posts on pages on mobile phones besides one page, page id 2461.

Please help.

Thanks.

Hi @Bark201,

Thanks for reaching out.

We don’t recommend disabling that, all javascript functionality relies on that. Slider, animation, grids, and etc. But if you insist then you may check this https://wordpress.stackexchange.com/questions/158453/deregister-scripts-on-certain-page, sample will be

add_action( 'wp_enqueue_scripts', 'my_register_javascript', 100 );

function my_register_javascript() {
   if ( is_singular('post') ) {

       wp_deregister_script( 'jquery' );

     }
}

Thanks.

I think you misread what I wrote. I want to disable jquery.js only on mobile phones and to allow it in only 2 pages on mobile phones.

Hi @Bark201

Then you need to rewrite the code mentioned above with these two functions:
wp_is_mobile()
and
is_page()

Check these references:

https://developer.wordpress.org/reference/functions/wp_is_mobile/

https://developer.wordpress.org/reference/functions/is_page/

As this is all custom development, regretfully we wont be able to assist further. Custom development is outside the scope of our support. Were happy to provide advice and get you started in the right direction, but you would still be responsible for the implementation. And moreover, this solution may not work after several updates especially if the themes structure changed or overridden.

Thanks.

ok, thanks.

You are welcome :slight_smile:

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.