How To Remove Scripts On Mobile Devices

I use responsive viewport tags for my blogs and they’ve been working every well across all mobile devices. I have a jQuery called imgPreview and it works quite well on Desktops and tablets, but not well on small devices like iPhones, Android Phones, iPod Touches. I created a footer-phone.php to remove all scripts that don’t work well for small width devices. Now I need to load the footer-phone.php for all small mobile devices.

WordPress has wp_is_mobile() that works quite well for detecting mobile devices, but I want the imgPreview to work with Tablets: iPads, Android and Windows tablets. Mobile_Detect.php comes handy since it detects phones and tablets.

This is how I did mine and it seems to work very well, imgPreview works on Desktop and iPads, Android pads.


  1. Download Mobile_Detect.php to the theme root folder.
  2. Add these codes to Theme function.php. (credit to Astrotim)


    function md_is_mobile() {$detect = new Mobile_Detect;

    if( $detect->isMobile() && !$detect->isTablet() ){
    return true;
    } else {
    return false;



  3. Since imgPreview only exists in single page only, so we need to redirect footer-phone.php in Theme single.php.

    if (md_is_mobile()){


  4. When the single.php is loaded, the function.php will check for mobile, desktop and tablet devices: footer-phone.php will be loaded for mobile, footer-single.php for desktop and tablet devices.

z_footer_single_php          z_footer_phone_php


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.