Skip to content

Instantly share code, notes, and snippets.

@kel
Created September 21, 2016 17:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kel/3826b01b1bbd3d1b949773c019b87491 to your computer and use it in GitHub Desktop.
Save kel/3826b01b1bbd3d1b949773c019b87491 to your computer and use it in GitHub Desktop.
/**
* Change the URL for static files to use the CDN
*/
if (FIT_USE_CDN)
{
add_filter('theme_root_uri', 'fit_cdn_rewrite', 99, 1);
add_filter('wp_get_attachment_image_src', 'fit_cdn_image_rewrite', 99, 1);
add_filter('the_content', 'fit_cdn_content_rewrite', 99, 1);
}
function fit_cdn_rewrite($url) {
$url = str_replace(get_site_url(), FIT_CDN_URL, $url);
return $url;
}
function fit_cdn_image_rewrite($image) {
$image[0] = str_replace(get_site_url(), FIT_CDN_URL, $image[0]);
return $image;
}
function fit_cdn_content_rewrite($content) {
$content = str_replace(get_site_url() . '/wp-content/', FIT_CDN_URL . '/wp-content/', $content);
return $content;
}
define('FIT_USE_CDN', true);
define('FIT_CDN_URL', 'http://cdn.domain.com');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment