Title: Yet another srcset question ;)
Last modified: September 1, 2016

---

# Yet another srcset question ;)

 *  [SH10151](https://wordpress.org/support/users/sh10151/)
 * (@sh10151)
 * [9 years, 11 months ago](https://wordpress.org/support/topic/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? ([https://wordpress.org/support/topic/is-it-possible-to-disable-the-responsive-image-srcset-on-wordpress-44?replies=25](https://wordpress.org/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="http://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="http://www.mysite.com/wp-content/uploads/
   2016/06/bar-wall.jpeg 778w, http://www.mysite.com/wp-content/uploads/2016/06/
   bar-wall-300x169.jpeg 300w" sizes="(max-width: 778px) 100vw, 778px">`
 * [https://wordpress.org/plugins/dreamspeed-cdn/](https://wordpress.org/plugins/dreamspeed-cdn/)

Viewing 1 replies (of 1 total)

 *  Thread Starter [SH10151](https://wordpress.org/support/users/sh10151/)
 * (@sh10151)
 * [9 years, 11 months ago](https://wordpress.org/support/topic/yet-another-srcset-question/#post-7511987)
 * 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('http://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://wordpress.org/support/topic/not-working-for-new-srcset-attribut-possible-workaround?replies=6](https://wordpress.org/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.

 * ![](https://s.w.org/plugins/geopattern-icon/dreamspeed-cdn_3c83a7.svg)
 * [DreamSpeed CDN (RETIRED)](https://wordpress.org/plugins/dreamspeed-cdn/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/dreamspeed-cdn/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/dreamspeed-cdn/)
 * [Active Topics](https://wordpress.org/support/plugin/dreamspeed-cdn/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/dreamspeed-cdn/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/dreamspeed-cdn/reviews/)

## Tags

 * [srcset](https://wordpress.org/support/topic-tag/srcset/)

 * 1 reply
 * 1 participant
 * Last reply from: [SH10151](https://wordpress.org/support/users/sh10151/)
 * Last activity: [9 years, 11 months ago](https://wordpress.org/support/topic/yet-another-srcset-question/#post-7511987)
 * Status: not resolved