Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/**
* 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
You can’t perform that action at this time.