Device: how to deactivate plugins depending on the device
Freesoul Deactivate Plugins gives you the possibility to disable specific plugins when the page is loaded by a mobile or desktop device (desktop only for PRO users).
In the example above the plugin Change Class In Viewport will not run when the site is visited by a mobile device.
The other plugins will be managed by the other settings.
Freesoul Deactivate Plugins considers tablets and mobile phones both as mobile devices.
Be very careful when you use those options, you risk two issues:
- You have a caching plugin that doesn’t distinguish between mobile and desktop. When the first user visits the page with a mobile device, the page is saved in the server cache. Then other users visit the same page with a desktop, but they see the mobile version.
- You disable plugins on the mobile version, but you see ugly orphan shortcodes. If e.g. you disable Revolution Slider on mobile you will see something that looks like [revslider alias=”example-alias”] instead of the original slider.
To avoid the first issue you should use a caching plugin that distinguishes between mobile and desktop, as e.g. W3 Total Cache or WP Fastest Cache (the free version of WP Fastest Cache distinguishes between desktop and mobile, but it doesn’t save the mobile cache, the premium version does it).
To avoid the second issue, you can install Specific Content For Mobile, then you will see the mobile versions in the Single Settings and disable specific mobile versions and not only for all mobile devices. And you will be able to customize the mobile versions, removing the content that would generate the orphan shortcodes.
Another way to solve the second issue is writing custom code in functions.php of your child theme or in a functional plugin, Remember that if you need to create a functional plugin you can do it in Freesoul Deactivate Plugins => Tools => Create Custom Plugin. Read here for more details.
You can use the constant “EOS_{PLUGIN-SLUG}_ACTIVE” to check if a plugin is globally active but disabled only on mobile devices.
Replace {PLUGIN-SLUG} with the slug of the plugin you want to check. The slug is the name of the plugin main folder but with all capital letters.
Let’s suppose you disable REVSLIDER on mobile
In this case, you can write this code:
if( wp_is_mobile() ){ if( defined( 'EOS_REVSLIDER_ACTIVE' ) && EOS_REVSLIDER_ACTIVE ){ //Whatever you need to fire add_shortcode( 'rev_slider','__return_false' ); //e.g if you need to remove orphan shortcodes on mobile } }
We are saying: if it’s a mobile and Revolution Slider is globally active but disabled on mobile, then return nothing as the output of the shortcode “rev_slider”.
Of course, we need to know the name of the shortcode.
The constant that in this example is EOS_REVSLIDER_ACTIVE will be suggested in the mobile settings page.