Fix iOS resizing bug

On iOS devices (iPhone, iPad), you only need to include the meta viewport tag for it to initially load properly. But if you rotate the device after loading, it will resize and be slightly too zoomed in. The code below fixes this.

<?php
/**
* Enqueue iOS bug fix
*
*/
function be_enqueue_ios_bug_fix() {
wp_enqueue_script( 'be-ios-bug', get_stylesheet_directory_uri() . '/lib/js/ios-bug.js' );
}
add_action( 'wp_enqueue_scripts', 'be_enqueue_ios_bug_fix' );
view raw functions.php hosted with ❤ by GitHub
(function(doc) {
var addEvent = 'addEventListener',
type = 'gesturestart',
qsa = 'querySelectorAll',
scales = [1, 1],
meta = qsa in doc ? doc[qsa]('meta[name=viewport]') : [];
function fix() {
meta.content = 'width=device-width,minimum-scale=' + scales[0] + ',maximum-scale=' + scales[1];
doc.removeEventListener(type, fix, true);
}
if ((meta = meta[meta.length - 1]) && addEvent in doc) {
fix();
scales = [.25, 1.6];
doc[addEvent](type, fix, true);
}
}(document));
view raw ios-bug.js hosted with ❤ by GitHub

javascript responsive

Bill Erickson

Bill Erickson is a freelance WordPress developer and a contributing developer to the Genesis framework. For the past 14 years he has worked with attorneys, publishers, corporations, and non-profits, building custom websites tailored to their needs and goals.

Ready to upgrade your website?

I build custom WordPress websites that look great and are easy to manage.

Let's Talk