• 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? (https://www.ads-software.com/support/topic/is-it-possible-to-disable-the-responsive-image-srcset-on-wordpress-44?replies=25)

    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="https://cdn.mysite.com/wp-content/uploads/2016/06/bar-wall.jpeg" class="attachment-clean-box-featured size-clean-box-featured wp-post-image" alt="bar-wall" srcset="https://www.mysite.com/wp-content/uploads/2016/06/bar-wall.jpeg 778w, https://www.mysite.com/wp-content/uploads/2016/06/bar-wall-300x169.jpeg 300w" sizes="(max-width: 778px) 100vw, 778px">

    https://www.ads-software.com/plugins/dreamspeed-cdn/

Viewing 1 replies (of 1 total)
  • Thread Starter SH10151

    (@sh10151)

    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('https://www', 'https://cdn', $sources[ $source['value'] ][ 'url' ]);
    		// you MAY use external domains as well
    		// $sources[ $source['value'] ][ 'url' ] = str_replace('https://www.example.com', 'https://static.examplecdnprovider.com', $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:
    https://www.ads-software.com/support/topic/not-working-for-new-srcset-attribut-possible-workaround?replies=6

    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.