I have the below filter added to my theme's functions.php file:
function cdn_upload_url() {
if ( ! is_admin() ) {
return 'http://d24fxnpb2c5viy.cloudfront.net';
}
}
add_filter( 'pre_option_upload_url_path', 'cdn_upload_url' , 10);
After upgrading to WordPress 4.7, this filter no longer fires.
Do pre_option_{option}
filters no longer work in 4.7?
Any help greatly appreciated.
add_filter('upload_dir', 'cdn_upload_url'); function cdn_upload_url($args) { if (!is_admin()) { $args['baseurl'] = 'https://your-awesome-cdn.net/wp-content/uploads'; } return $args; }
– Hypallageif (!is_admin())
is important but you may want to check user roles as well. If you have an organization with editors, you may not want to have them reading from the CDN URL either since it takes a while for assets to propagate to a CDN – Hypallage