{"id":5427,"date":"2016-01-22T14:11:14","date_gmt":"2016-01-22T22:11:14","guid":{"rendered":"http:\/\/www.dognmonkey.com\/techs\/?p=5427"},"modified":"2016-02-05T13:33:38","modified_gmt":"2016-02-05T21:33:38","slug":"how-to-remove-scripts-on-mobile-devices","status":"publish","type":"post","link":"https:\/\/www.dognmonkey.com\/techs\/how-to-remove-scripts-on-mobile-devices.html","title":{"rendered":"How To Remove Scripts On Mobile Devices"},"content":{"rendered":"<p>I use responsive viewport tags for my blogs and they&#8217;ve been working every well across all mobile devices. I have a jQuery called <a href=\"\/\/james.padolsey.com\/demos\/imgPreview\/full\/\" target=\"_blank\">imgPreview<\/a> 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&#8217;t work well for small width devices. Now I need to load the footer-phone.php for all small mobile devices.<\/p>\n<p>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. <a href=\"https:\/\/github.com\/serbanghita\/Mobile-Detect\/blob\/master\/Mobile_Detect.php\" target=\"_blank\">Mobile_Detect.php<\/a> comes handy since it detects phones and tablets.<\/p>\n<p>This is how I did mine and it seems to work very well, imgPreview works on Desktop and iPads, Android pads.<\/p>\n<p style=\"text-align: center;\"><a class=\"preview\" href=\"\/\/www.dognmonkey.com\/techs\/wp-content\/uploads\/2016\/01\/z_theme_root.jpg\" rel=\"lightbox[md]\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-thumbnail wp-image-5434\" src=\"\/\/www.dognmonkey.com\/techs\/wp-content\/uploads\/2016\/01\/z_theme_root-200x112.jpg\" alt=\"z_theme_root\" width=\"200\" height=\"112\" \/><\/a><\/p>\n<ol>\n<li>Download Mobile_Detect.php to the theme root folder.<\/li>\n<li>Add these codes to Theme function.php. (<a href=\"\/\/stackoverflow.com\/users\/943577\/astrotim\" target=\"_blank\">credit to Astrotim<\/a>)<br \/>\n<blockquote><p>require_once(&#8216;Mobile_Detect.php&#8217;);<\/p>\n<p>function md_is_mobile() {$detect = new Mobile_Detect;<\/p>\n<p>if( $detect-&gt;isMobile() &amp;&amp; !$detect-&gt;isTablet() ){<br \/>\nreturn true;<br \/>\n} else {<br \/>\nreturn false;<br \/>\n}<br \/>\n}<\/p>\n<p style=\"text-align: center;\"><a class=\"preview\" href=\"\/\/www.dognmonkey.com\/techs\/wp-content\/uploads\/2016\/01\/z_function_php_mod.jpg\" rel=\"lightbox[md]\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-thumbnail wp-image-5435\" src=\"\/\/www.dognmonkey.com\/techs\/wp-content\/uploads\/2016\/01\/z_function_php_mod-200x112.jpg\" alt=\"z_function_php_mod\" width=\"200\" height=\"112\" \/><\/a><\/p>\n<p>&nbsp;<\/p><\/blockquote>\n<\/li>\n<li>Since imgPreview only exists in single page only, so we need to redirect footer-phone.php in Theme single.php.<br \/>\n<blockquote><p>&lt;?php<br \/>\nif (md_is_mobile()){<br \/>\nget_footer(phone);}else{get_footer(single);}<br \/>\n?&gt;<\/p>\n<p style=\"text-align: center;\"><a class=\"preview\" href=\"\/\/www.dognmonkey.com\/techs\/wp-content\/uploads\/2016\/01\/z_single_php_mod.jpg\" rel=\"lightbox[md]\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-thumbnail wp-image-5436\" src=\"\/\/www.dognmonkey.com\/techs\/wp-content\/uploads\/2016\/01\/z_single_php_mod-200x112.jpg\" alt=\"z_single_php_mod\" width=\"200\" height=\"112\" \/><\/a><\/p>\n<\/blockquote>\n<\/li>\n<li>\n<blockquote><p>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.<\/p><\/blockquote>\n<\/li>\n<\/ol>\n<p style=\"text-align: center;\"><a class=\"preview\" title=\"footer-single.php with ipreview scripts\" href=\"\/\/www.dognmonkey.com\/techs\/wp-content\/uploads\/2016\/01\/z_footer_single_php.jpg\" rel=\"lightbox[md]\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-thumbnail wp-image-5438\" src=\"\/\/www.dognmonkey.com\/techs\/wp-content\/uploads\/2016\/01\/z_footer_single_php-200x112.jpg\" alt=\"z_footer_single_php\" width=\"200\" height=\"112\" \/><\/a>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0<a class=\"preview\" title=\"footer-phone.php without ipreview scripts\" href=\"\/\/www.dognmonkey.com\/techs\/wp-content\/uploads\/2016\/01\/z_footer_phone_php.jpg\" rel=\"lightbox[md]\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-thumbnail wp-image-5439\" src=\"\/\/www.dognmonkey.com\/techs\/wp-content\/uploads\/2016\/01\/z_footer_phone_php-200x112.jpg\" alt=\"z_footer_phone_php\" width=\"200\" height=\"112\" \/><\/a><\/p>\n<ul class=\"lcp_catlist\" id=\"lcp_instance_0\"><\/ul>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I use responsive viewport tags for my blogs and they&#8217;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&#8217;t <a href=\"https:\/\/www.dognmonkey.com\/techs\/how-to-remove-scripts-on-mobile-devices.html\" class=\"more-link\">&#8230;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[807,26,20],"tags":[800,802,795,801],"class_list":["post-5427","post","type-post","status-publish","format-standard","hentry","category-scripts","category-themes","category-wordpress","tag-imgpreview","tag-mobile_detect-php","tag-responsive-theme","tag-wp_is_mobile"],"views":328,"_links":{"self":[{"href":"https:\/\/www.dognmonkey.com\/techs\/wp-json\/wp\/v2\/posts\/5427","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dognmonkey.com\/techs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dognmonkey.com\/techs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dognmonkey.com\/techs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dognmonkey.com\/techs\/wp-json\/wp\/v2\/comments?post=5427"}],"version-history":[{"count":3,"href":"https:\/\/www.dognmonkey.com\/techs\/wp-json\/wp\/v2\/posts\/5427\/revisions"}],"predecessor-version":[{"id":5444,"href":"https:\/\/www.dognmonkey.com\/techs\/wp-json\/wp\/v2\/posts\/5427\/revisions\/5444"}],"wp:attachment":[{"href":"https:\/\/www.dognmonkey.com\/techs\/wp-json\/wp\/v2\/media?parent=5427"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dognmonkey.com\/techs\/wp-json\/wp\/v2\/categories?post=5427"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dognmonkey.com\/techs\/wp-json\/wp\/v2\/tags?post=5427"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}