Rewrite WP-Minify URLs for CSS and JS Offloading

If you want to offload your combined and minified javascript and CSS files to a separate domain or a content delivery network (CDN), WP-Minify provides you with a handy set of filters (place this in your theme’s functions.php):

add_filter('wp_minify_js_url', 'offload_minify_js_css');
add_filter('wp_minify_css_url', 'offload_minify_js_css');

function offload_minify_js_css($url) {
	return str_replace('domain.com', 'static.domain.com', $url);
}

Use Contact Form 7 to collect business leads and enquiries? I created Storage for Contact Form 7 plugin which stores them safely in WordPress database.

Get it now for only $19 →

2 Comments

  1. Mike Hudson says:

    Just thought I’d let you know I appreciate you taking the time to post this – I was close (using pre_replace as opposed to str_replace) but your solution works a treat.

  2. Sohail Amir says:

    I’m so glad you posted this! The W3 Cache plugin really wasn’t doing a good job and the CDN off linker plugins weren’t making any difference. This little bit of code makes a huge difference so thanks a load.

Leave a Reply