Replace Thumbnail URL
Wordpress plugin to replaces the site URL with a custom one in attachment image URLs
Install
This is the repository archive. It installs, but the folder name will carry the branch suffix and updates will not flow.
Install straight from GitHub with WP-CLI:
wp plugin install https://github.com/abidarm/replace-thumbnail-url/archive/refs/heads/main.zipWordPress plugin that rewrites attachment image URLs to use a custom domain (for example a CDN or public site URL) instead of the current site URL.
Works as a standard plugin or as a must-use (mu) plugin.
Requirements
| Requirement | Version |
|---|---|
| WordPress | 5.0 or higher |
| PHP | 7.4 or higher |
Features
- Rewrites domains in attachment URLs (
wp_get_attachment_url) - Rewrites sized image
srcvalues (wp_get_attachment_image_src/ related helpers) - Rewrites
srcsetURLs (wp_calculate_image_srcset) - Settings field under Settings → Media to set the custom media domain
- Defaults to the current site URL (no rewrite) until you change it
Installation
Standard plugin
- Copy the
replace-thumbnail-urlfolder intowp-content/plugins/. - In Plugins, activate Replace Thumbnail URL.
- Go to Settings → Media and set Custom media domain if needed.
Must-use (mu) plugin
Must-use plugins load automatically and cannot be deactivated from the admin UI.
WordPress only autoloads PHP files directly in wp-content/mu-plugins/ (not in subfolders).
Option A — single file
- Copy
replace-thumbnail-url.phpintowp-content/mu-plugins/. - Done. The plugin is active on every request.
Option B — keep the folder (recommended if you want the README nearby)
- Copy the whole
replace-thumbnail-urlfolder intowp-content/mu-plugins/replace-thumbnail-url/. - Add a loader at
wp-content/mu-plugins/replace-thumbnail-url-loader.php:
<?php
/**
* Plugin Name: Replace Thumbnail URL (MU loader)
* Description: Loads Replace Thumbnail URL as a must-use plugin.
*/
require_once __DIR__ . '/replace-thumbnail-url/replace-thumbnail-url.php';
- Done. Settings remain available under Settings → Media.
Configuration
- Open Settings → Media.
- Find Attachment URL domain.
- Set Custom media domain to the public/CDN base URL (no trailing slash required).
- Save changes.
Leave the field as the current site URL (or empty, which falls back to the site URL) to disable rewriting.
How it works
When a custom domain differs from site_url(), the plugin replaces the site URL prefix in:
- Attachment file URLs
- Attachment image
srcURLs - Responsive image
srcsetURLs
Stored attachment paths in the database are not changed; only URLs returned by WordPress filters are rewritten on output.
Author
License
Use and modify as needed for your projects.
Releases
1 release.
These releases are tags only. The author does not attach a packaged zip, so there are no download counts to report.