Created
May 17, 2010 20:29
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It doesn't work with Storefront theme.