#34757 closed defect (bug) (worksforme)
Add filter, probably image_downsize, for image urls in wp_calculate_image_srcset()
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 4.4 |
Component: | Media | Keywords: | |
Focuses: | Cc: |
Description
I am able to use the image_downsize filter to return custom images stored outside the wp-uploads directory.
The wp_calculate_image_srcset() calculate the image sources to include in a 'srcset' attributes; images sources are not in sync with the image_downsize filter.
Change History (3)
#2
@
9 years ago
- Resolution set to worksforme
- Status changed from new to closed
Thanks!
// Change imges urls in scrset function re_calculate_image_srcset($sources, $size_array, $image_src, $image_meta, $attachment_id) { if ( eazyest_folderbase()->is_gallery_image( $attachment_id ) ) { $uploads_url = wp_upload_dir(); $uploads_url = trailingslashit( $uploads_url['baseurl'] ); foreach ($sources as $key => $value) { $sources[$key]['url'] = str_replace($uploads_url, eazyest_gallery()->address(), $value['url'] ); } } return $sources; } add_filter('wp_calculate_image_srcset', 're_calculate_image_srcset', 100, 5);
Note: See
TracTickets for help on using
tickets.
Hi @klihelp,
wp_calculate_image_srcset()
contains it's own filter, named 'wp_calculate_image_srcset', which can be used to modify the URLs of images included in thesrcset
attribute. The filter passes each source as an array containing the URL, the descriptor value (the image width in pixels), and a character representing the descriptor type (i.e., 'w').