25% off ProSNIPC25OFF

Enable Pinch-to-Zoom on Mobile

Replaces any restrictive viewport meta tag (one that sets user-scalable=no or maximum-scale=1) with a permissive one that allows pinch-to-zoom.

PHPby SnipCraft
php
<?php
if ( ! function_exists( 'scseed_enable_pinch_zoom' ) ) {
    /**
     * Buffers page output and replaces any viewport meta tag that disables
     * pinch-to-zoom (user-scalable=no / maximum-scale=1) with a permissive one.
     * Improves accessibility and passes Google's mobile-usability audit.
     */
    function scseed_enable_pinch_zoom_buffer() {
        ob_start( 'scseed_viewport_meta_replace' );
    }

    function scseed_viewport_meta_replace( $html ) {
        // Match any <meta name="viewport" ...> tag (self-closing or not).
        $pattern     = '/<meta[^>]+name=["']viewport["'][^>]*/?>/i';
        $replacement = '<meta name="viewport" content="width=device-width, initial-scale=1">';
        $replaced    = preg_replace( $pattern, $replacement, $html, 1 );
        return $replaced !== null ? $replaced : $html;
    }

    add_action( 'template_redirect', 'scseed_enable_pinch_zoom_buffer' );
}
#accessibility#mobile#responsive#viewport#zoom