goranseric
1/14/2016 - 5:09 PM

Premodify URLs on WPEngine to directly point to your CDN. Avoids issues some link generators have with HTTP redirects.

Premodify URLs on WPEngine to directly point to your CDN. Avoids issues some link generators have with HTTP redirects.

<?php
function wpe_noRedirectUrl($srcURL)
{
    if (class_exists('WpeCommon')) {
        global $wpe_netdna_domains;
        static $cdn_domain;

        if (!isset($cdn_domain)) {
            $wpe_common = new WpeCommon();
            if ($wpe_common->is_cdn_enabled()) {
                $cdn_domain = $wpe_common->get_cdn_domain($wpe_netdna_domains, get_bloginfo('url'));
            }
        }

        if ($cdn_domain) {
            $srcURL = preg_replace('/' . preg_quote(get_bloginfo('url'), '/') . '/', (is_ssl() ? 'https://' : 'http://') . $cdn_domain, $srcURL);
        }
    }

    return $srcURL;
}