How can I disable a plugin only for mobiles divices

Hi
I`d like disable completely a plugin when users are connected from mobile device.
I know I can use the following CSS for to apply changes only in mobiles device:
@media screen and (max-width:782px)
But I dont know if I can use this code for disable a plugin...
In my case I want disable the plugin:
https://wordpress.org/plugins/admin-bar-login/
If I can disable plugin for mobiles devices with CSS, I`d like know the complete code.
Can you provide me that?
Or, alternatively same other solution?
Thanks very much for your support.

  • Sajid
    • DEV MAN’s Sidekick

    Hello Francesc Prada,
    Hope you are doing good today :slight_smile:

    It is not possible with CSS media queries because CSS code only execute on client side (browser only) and not server side.

    However, I come up with following quick snippet code for you to disable Admin Bar Login plugin on mobile devices. I have not tested though but should work.

    Download the following snippet from github, extract on your computer and copy the file from extracted folder and upload to /wp-content/mu-plugins folder (create if this folder does not exists) via FTP or FileManager of cPanel to use as mu-plugin. No need to do any thing else, this will run automatically.
    https://gist.github.com/sjaved87/ad6cfcc2241c78af8efe1a212048e56c

    You can also just copy the code from gist and paste in functions.php file of your child theme.

    Best Regards,
    Sajid

  • Francesc Prada
    • Design Lord, Child of Thor

    Hi Sajid
    first, thanks for your fast reply.
    I have copy your code into the funcions.php of my child theme.
    When I saved it, my web was broken (white page).
    Please, test your code in your web and tell me if it run.
    If you can, corrige the code and return it to me.
    Thanks very very much for your support.

  • Sajid
    • DEV MAN’s Sidekick

    Hello Francesc Prada,
    Hope you are doing good today :slight_smile:

    Yes, I did run it once on my own localhost WordPress single site and then I gave you the code.

    However, it seems the function is not available for WordPress MultiSites. I tried to run on a MultiSites website and it broke it with blank screen.

    Any way, I have come up with a different solution for you and it tested it on my MultiSites and it worked fine. It did deactivate the plugin too while viewing the site on mobile device.

    Please use the updated code from here and then check:
    https://gist.github.com/sjaved87/ad6cfcc2241c78af8efe1a212048e56c

    Best Regards,
    Sajid

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.