How to Deactivate plugins when using a Mobile Theme

How to Deactivate plugins when using a Mobile Theme

Mobile theme plugins are great. They allow us to instantly change our sites from their regular desktop version into a more mobile friendly format, but the trouble is that sometimes we don’t want all our regular desktop plugins to run when our sites are being viewed in mobile mode.

I’ve come across this situation myself using Click Missile when the original desktop site is set up using one of the many available numerous WordPress Adsense Plugins (such as WP-insert, Adsense Now! etc), and I want to just use Click Missile to take care of serving the mobile ads.

Double Ad Trouble!

What can happen is that both Click Missile and the Adsense Plugin insert their ads into the content of the mobile site, effectively doubling up the ads. We don’t really want that to happen. What’s actually required is that the Adsense plugin gets switched off temporarily and Click Missile just takes over and serves the ads. Of course most Adsense plugins do not have the capability to switch themselves off when being viewed on a mobile.

The Plugin Solution

What’s required is a plugin that can automatically detect if the site is being viewed on a mobile smartphone then switch off the Adsense plugin. Its useful for anyone who needs to do this, not just Click Missile users.

Why Don’t I Just Build This Capability Into Click Missile?

In order to turn off plugins temporarily we need to filter them out of WordPress’s active plugins array before the plugins themselves have been activated. It needs to happen even before Click Missile has been activated. So with this in mind I’ve built it into a basic ‘MU Plugin’ as a seperate entity. It’s also an interesting idea to develop into a seperate plugin with more features.

What is a ‘MU Plugin’?

A MU Plugin is a ‘Must Use’ plugin which is always activated in a WordPress install and runs before any other plugin run.

So to the Plugin..

Introducing HMT Plugin Zapper

What does it do?

  • Detects whether a site is being viewed on a mobile device using the Detect Mobile Browsers script from Chad Smith. (Thanks Chad!)
  • Removes Adsense Plugins from the WordPress Active Plugins array so that they won’t run when the site is being viewed on mobile.

Which Plugins will it Zap?

I’ve hardcoded in all the most popular Adsense plugins from the WordPress repository that I could find. I’m bound to have missed some though, so feel free to tell me if you have a particular one you want to be zapped at mobile site viewing time.

Currently in the Zap list are:

  • Easy Adsense
  • Adsense Extreme
  • Awesome Ads
  • Adsense Now
  • Ad Sense
  • Quick Adsense
  • Quick Adsene Cn
  • Adsense Manager
  • WP Adsense Plugin
  • All In One Adsense and YPN Pro
  • Insert Adsense
  • Adsense Insert
  • Google Adsense Plug and Play
  • Adsense Optimiser
  • Awesome Google Adsense
  • Google Adsense Plugin
  • TentBlogger Simple Adsense
  • Easy Ads
  • Ad Injection
  • WP Insert
  • Easy Advertisement Insert
  • WP Auto Post Ads
  • Ad Rotate
  • Google Adsense

Using the Plugin

There is NO SETTINGS PAGE for this plugin. Just install it and go! If you want to add more plugins to zap see the instructions further down this page.

Downloading and Installing HMT Plugin Zapper

Before you start its important to know you will have to install this plugin via FTP or your web host cpanel. You cannot install this plugin using the WordPress plugin installer as it needs to be loaded in the MU Plugins folder.

  1. mu-plugins-file-structureGrab the HMT Plugin Zapper zip file and unzip it.
  2. Connect to your site using FTP or your web host cpanel.
  3. Navigate to your sites wp-content folder.
  4. Look for the mu-plugins folder. It should be right there in the wp-content folder.
  5. If it doesn’t exist already create the mu-plugins folder in the wp-content folder.
  6. Navigate into the mu-plugins folder and upload hmt-plugin-zapper.php into it.

The plugin will be activated as soon as you place it in the mu-plugins folder.


Make sure you read install instructions above first though!

>> Download hmt-plugin-zapper-build-100112

Adding More Plugins To Zap

You can add and delete your own plugins from the removal list this way:

  • Open the PHP source code of the plugin in hmt-plugin-zapper.php
  • Scroll down to the CONFIGURE PLUGINS TO REMOVE HERE section
  • If you look closely at the code you will see where to add your own plugins or delete the ones that are there. Its just a matter of copying the line of code which zaps the plugin.
  • Each plugin to be zapped is identified by its folder and php file name.
    If you are adding a new plugin then you can find its folder and filename in the WordPress Admin Area by clicking on PLUGINS and then clicking on EDIT for the plugin of your choice. You will see the plugin folder and filename at the top of the page.
  • Upload your edited file to your server into the wp-content/mu-plugins folder

Perpetual Beta

I’ve tested this plugin with as many plugin / theme combos as I can, and it works for me. Consider it a perpertual beta version though 😉

Future Development of the Idea

The idea of a plugin which can zap other plugins under certain circumstances is an interesting one (not just for mobile detection), so if enough people are interested I may develop it further to give it a nice interface for selecting and zapping plugins in other circumstances.

Also if you know a method of zapping a plugin even after plugins have been loaded I’d be most interested to hear it.

3 Comments on “How to Deactivate plugins when using a Mobile Theme

  1. Hi!
    I’m very like your plugin, it’s what i need
    but i have a problem. I’m using 2 wordpress theme, 1 is for pc, 2 is mobile vesion. I used your plugin to prevent a column shortcode plugin from loading in mobile version. but it didnt work for me, my plugin that i’m using is “Shortcode Column –
    My mobile version is Obox mobile plugin. I tested and it didnt work, when i remove your plugin, my home page in mobile version was affected, it’s display pc version in stead of mobile version when i surf by mobile.
    So, can you help me to check if your plugin have some effect to Column Shortcode plugin and Obox mobile version!

  2. OK it worked now but i have another problem, so sad!
    Plugin didn’t load, but its shortcode still appear in content on post, som what i have to do to completely remove it?

Leave a Reply