I call a lot of images with wp_get_attachment_image_src()
and would like to off load those images to a CDN.
Is there a filter to grab the URL and change it?
I call a lot of images with wp_get_attachment_image_src()
and would like to off load those images to a CDN.
Is there a filter to grab the URL and change it?
Comments are closed.
No, not strictly. You can check the source and see that there is no hook that would let you alter the URL.
You should also notice this interesting bit of code:
Follow the trail to here and you get this:
If you hook into
image_downsize
…… you should be able to return any URL you want, but it means you will need to duplicate more or less the whole of
image_downsize()
with changes of course.Just to clarify for anyone might stumble upon this in the future, as of 4.3.0 a filter to alter the image src does exist: wp_get_attachment_image_src
Note: To filter the srcset of an image use: wp_calculate_image_srcset