Skip to content

Instantly share code, notes, and snippets.

@pospi
Last active October 14, 2016 08:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save pospi/6547214 to your computer and use it in GitHub Desktop.
Save pospi/6547214 to your computer and use it in GitHub Desktop.
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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment