Skip to content

Instantly share code, notes, and snippets.

@2aces
Created January 6, 2016 22:02
Show Gist options
  • Save 2aces/b5ad64cf0d273a8bcf9f to your computer and use it in GitHub Desktop.
Save 2aces/b5ad64cf0d273a8bcf9f to your computer and use it in GitHub Desktop.
forces CDN subdomain for srcset file list on img element
// you MUST change static1 to your CDN subdomain as needed
function aafd_cdn_srcset($sources){
foreach ( $sources as $source ) {
$sources[ $source['value'] ][ 'url' ] = str_replace('http://www', 'https://static1', $sources[ $source['value'] ][ 'url' ]);
// you MAY use external domains as well
// $sources[ $source['value'] ][ 'url' ] = str_replace('http://www.example.com', 'https://static.examplecdnprovider.com', $sources[ $source['value'] ][ 'url' ]);
}
return $sources;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment