Image 'srcset' attribute not populated correctly in 4.4
-
I upgraded my blog to WordPress 4.4 today and a whole lot of images showed up as broken. I tracked it down to the ‘srcset’ attribute on img tags not being populated correctly. The Azure plugin basically adjusts the url for images to point it at the blob store. That adjustment works for ‘src’ but with the new reactive design stuff on ‘srcset’, those adjustments don’t get called.
This needs to get fixed as part of the plugin but, in the meantime, I implemented a pretty kludgy workaround to get back up and running again.
You can fix it by editing the ‘windows-azure-storage.php’ file and the following lines:
add_filter( 'wp_calculate_image_srcset', 'windows_azure_storage_wp_calculate_image_srcset', 9, 5 ); function windows_azure_storage_wp_calculate_image_srcset($sources, $size_array, $image_src, $image_meta, $attachment_id ) { $searchString = "www.benday.com/wp-content/uploads/D:homesitewwwroot/wp-content/uploads"; $replaceString = "bendayblog.blob.core.windows.net/wp-public"; $valueAfterReplacement = ""; foreach ( $sources as &$source ) { $valueAfterReplacement = str_replace($searchString, $replaceString, $source['url']); $source['url'] = $valueAfterReplacement; } return $sources; }
You’ll need to replace the
$searchString
and$replaceString
values with the appropriate strings for your blog and azure account.Hope this helps.
-Ben
[Signature moderated]
- The topic ‘Image 'srcset' attribute not populated correctly in 4.4’ is closed to new replies.