Support » Plugin: DreamSpeed CDN (RETIRED) » Yet another srcset question ;)

  • Mika, really awesome plugin, btw!

    I just set up with DreamObjects and am using the CDN and your plugin. I love it and everything works great except for this dreaded srcset issue.

    The regular img src tag is properly showing up as the CDN alias URL, which is great. But the theme / template I’m using is also using srcset tags since the page is responsive (and I’d really rather not change that).

    Has there been any progress on being able to change these srcset tags? Is there anything you can point me towards to look into it further myself, to help out a bit?

    Update: Does your code really need to check which size to write in, or can it just do a regex to change the domain name / subdomain to rewrite that only (ignoring the URI / specific image path and size)? Not that I want them disabled, but they talk about disabling srcsets altogether in this post – maybe there is something to be gleaned on how to replace the domain only in here? (

    Thanks again!

    Here’s the piece of the HTML that is in question (it’s the featured image of a post, not a gallery or anything):

    <img width="778" height="438" src="" class="attachment-clean-box-featured size-clean-box-featured wp-post-image" alt="bar-wall" srcset=" 778w, 300w" sizes="(max-width: 778px) 100vw, 778px">

Viewing 1 replies (of 1 total)
  • Actually, after a bit of poking around, I made this change to my functions.php file, which works:

    // This replaces the srcset tags with the DreamObjects CDN domain (alias):
    // This is also where I could change all image URLs over to be secure links (HTTPS)
    function change_cdn_srcset($sources) {
    	foreach ( $sources as $source ) {
    		$sources[ $source['value'] ][ 'url' ] = str_replace('http://www', 'http://cdn', $sources[ $source['value'] ][ 'url' ]);
    		// you MAY use external domains as well
    		// $sources[ $source['value'] ][ 'url' ] = str_replace('', '', $sources[ $source['value'] ][ 'url' ]);
    	return $sources;
    add_filter( 'wp_calculate_image_srcset', 'change_cdn_srcset');

    All it does is rewrite the subdomain from “www.” to “cdn.”, which is my CDN alias. It writes this in for all srcset image values.

    It is based on what this guy did:

    I know it’s not exactly what you were trying to do, Mika, with determining the particular image sizes, etc, but I don’t think that is necessary, is it? Anyway, it works for me for now.

    Hope this helps!

Viewing 1 replies (of 1 total)
  • The topic ‘Yet another srcset question ;)’ is closed to new replies.