Skip to content

Instantly share code, notes, and snippets.

@sivel
Created May 17, 2010 20:29
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sivel/404192 to your computer and use it in GitHub Desktop.
Save sivel/404192 to your computer and use it in GitHub Desktop.
Simple WordPress plugin for repointing resource URLs to a CDN pull style host
<?php
/*
Plugin Name: Sivel CDN
Plugin URI: http://sivel.net/
Description: Points media urls at a CDN
Version: 1.0
Author: Matt Martz
Author URI: http://sivel.net/
*/
$origin = 'http://sivel.net';
$cdn = 'http://cache.sivel.net';
if ( ! is_admin() ) :
add_filter('script_loader_src', 'change_source');
add_filter('style_loader_src', 'change_source');
add_filter('stylesheet_uri', 'change_source');
add_filter('stylesheet_directory_uri', 'change_source');
function change_source($src) {
global $origin, $cdn;
if ( ! stristr($src, '.php') )
$src = str_replace($origin, $cdn, $src);
return $src;
}
endif;
add_filter('pre_option_upload_url_path', 'cdn_upload_url');
function cdn_upload_url($url) {
global $origin, $cdn;
return str_replace($origin, $cdn, $url);
}
@retroriff
Copy link

It doesn't work with Storefront theme.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment