Running NGINX, Wordpress 4.75 after upgrading from a way older version of Wordpress, our images are being served locally and I would like to change that to our CDN.

In the past images that were uploaded to the blog were uploaded directly to our CDN using a plugin ( I think Offload S3 Lite ).

My goal is that I want post images, thumbnail etc URL to be served from our CDN and not local.

For example I have: https://test.com/blog/wp-content/uploads/2016/07/Wedding1-370x215.jpg

Needs to point to: https://cdn.test.com/blog/wp-content/uploads/2016/07/Wedding1-370x215.jpg

Before the wordpress site (was not updated for a while) was uploading images directly to the CDN (AWS S3 -> Cloudfront) now that we upgraded to 4.75 the images that get served are pointing to local url instead of our CDN url.

images are served through the functions like: the_post_thumbnail()

Which I believe uses wp_get_attachment_image under the hood. If I can included a function in my functions.php to rewrite image urls that could work too.

So how can I get the image urls to point to our CDN and instead of local url?

Thanks for your help!


You probably want to use the wp_get_attachment_thumb_url filter to rewrite the images that are attached to a post (like featured images or ones added via media manager.)

If there are other images in the content (like if someone copied and pasted HTML with an image tag) you can filter the_content and use RegEx to replace those URLs, but that's hopefully not going to be something you run into very much.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.