,

How to offload WordPress media without breaking image URLs

How to safely offload wordpress media urls without breaking image references in posts, srcset, products, and feeds.

Modern data center server racks

When you offload wordpress media urls are the thing most people get wrong. URLs in existing posts, in srcset, in WooCommerce product galleries, in REST responses, and in feeds all need to point at the right place. This guide explains how a well built offload plugin handles each one.

The risk you are guarding against

A naive offload changes URLs in the database. New posts get the new URL. Old posts still reference /wp-content/uploads/ paths that no longer serve files. The site looks half migrated forever.

A clean offload leaves the database alone and rewrites URLs at output time. Old and new posts both serve images from the CDN without ever touching the database.

Rewriting URLs on output

On every page render, WordPress runs filters on attachment URLs. A good offload plugin hooks those filters and replaces the local URL with the CDN URL. The post content is unchanged. Only what the browser sees is rewritten.

This approach is reversible. Disable the plugin and the local URLs come back. Re enable it and the CDN URLs return.

Handling srcset and responsive variants

Every srcset variant has its own URL. The rewrite has to walk through each one and replace them all. Miss one variant and mobile visitors see broken images.

Defyn Media Offload handles srcset rewriting and verifies object keys during URL rewriting, so srcset variants resolve correctly even if a variant was generated after the offload.

WooCommerce product galleries

Product galleries store image IDs, not URLs. The IDs resolve to URLs at render time. As long as your offload plugin hooks the right filter, gallery images rewrite correctly with no special handling.

the Defyn Media Offload plugin ships with WooCommerce specific handling for variation images and protected file downloads, which the more naive plugins skip.

REST and feeds

Headless WordPress front ends fetch image URLs through the REST API. RSS feeds include image URLs in enclosure tags. Both need the same rewriting. A complete offload plugin hooks both paths.

Test by fetching /wp-json/wp/v2/posts and looking at the featured media URL. It should already point at the CDN host.

Frequently asked questions

Can I offload wordpress media urls without changing the database?

Yes. URL rewriting on output achieves this. The database keeps the local URLs, the visitor sees the CDN URLs.

What about old links in the search index?

Search engines refetch URLs over time. Within a few weeks the CDN URLs replace the local ones in the index, which is what you want.

Will image search keep working?

Yes if the CDN URLs are accessible and canonical. Image search indexes the URL it sees on the page.

Do I need redirect rules?

No. The output rewriting handles everything. Redirect rules are a workaround for plugins that change the database directly.

Claire Smith Avatar
Sponsored Loved this story? Defyn turns articles like this into the websites your competitors wish they had. Talk to us → defyn.com.au