Disable PrettyPhoto Script on Mobile Devices

Overview

This article describes how to disable the prettyPhoto Lighbox script within your Sterling or Karma WordPress Theme when viewing on a mobile device.

General Instructions:

  1. Open up the following theme file in your favorite code editor: /framework/js/custom-main.js
  2. For Sterling Theme – Scroll to line 16 and remove the following code:
     jQuery("a[data-gal^='prettyPhoto']").prettyPhoto({social_tools: false}); 
  3. For Karma Theme – Scroll to line 25 and remove the following code:
     jQuery("a[data-gal^='prettyPhoto']").prettyPhoto({hook:"data-gal"}); 
  4. For Sterling Theme – Scroll to a blank space within the custom-main.js file and add the code listed below. Save the file and you’re all good to go 🙂
  5.  var isMobile = {     Android: function() {         return navigator.userAgent.match(/Android/i);     },     BlackBerry: function() {         return navigator.userAgent.match(/BlackBerry/i);     },     iOS: function() {         return navigator.userAgent.match(/iPhone|iPad|iPod/i);     },     Opera: function() {         return navigator.userAgent.match(/Opera Mini/i);     },     Windows: function() {         return navigator.userAgent.match(/IEMobile/i);     },     any: function() {         return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows());     } };  jQuery(document).ready(function(){ if( !isMobile.any()){     jQuery("a[data-gal^='prettyPhoto']").prettyPhoto({social_tools: false});     } }); 
  6. For Karma Theme – Scroll to a blank space within the custom-main.js file and add the code listed below. Save the file and you’re all good to go 🙂
 var isMobile = {     Android: function() {         return navigator.userAgent.match(/Android/i);     },     BlackBerry: function() {         return navigator.userAgent.match(/BlackBerry/i);     },     iOS: function() {         return navigator.userAgent.match(/iPhone|iPad|iPod/i);     },     Opera: function() {         return navigator.userAgent.match(/Opera Mini/i);     },     Windows: function() {         return navigator.userAgent.match(/IEMobile/i);     },     any: function() {         return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows());     } };  jQuery(document).ready(function(){ if( !isMobile.any()){ 	jQuery("a[data-gal^='prettyPhoto']").prettyPhoto({hook:"data-gal"});     } });