WP Manifestindependent plugin directory
manifest / updates / domain-substitution-for-wordpress

Domain Substitution for WordPress

Substitutes the current domain with a custom domain for all attachment/image URLs; great for running a staging or local development site with images from your live/production site.

★ 0stars

Install

Download source zip No release zip yet

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/yllus/domain-substitution-for-wordpress/archive/refs/heads/main.zip
No built-in updater. New versions won't appear under Dashboard → Updates. Install new releases yourself, or let Git Updater track the repository.

A WordPress plugin that substitutes the current domain with a custom domain for all attachment/image URLs; great for running a staging or local development site with images from your live/production site.

Features

  • Replaces site domain with custom domain for all attachment URLs
  • Works with image srcset for responsive images
  • Processes content to replace image URLs in posts and pages
  • Perfect for staging/development environments using production images
  • Simple settings page for easy configuration
  • Lightweight with minimal performance impact

Installation

  1. Upload the domain-substitution-for-wordpress folder to /wp-content/plugins/
  2. Activate the plugin through the 'Plugins' menu in WordPress
  3. Go to Settings → WP Domain Substitution
  4. Enter your custom domain (e.g., cdn.example.com or your production site domain)
  5. Save settings

Usage

For Site Administrators

  1. Navigate to Settings → WP Domain Substitution in your WordPress admin
  2. Enter the custom domain you want to use for images (without http:// or https://)
  3. Click "Save Changes"
  4. All attachment and image URLs will now use the custom domain

Common Use Cases

Staging Site with Production Images

  • Problem: You're running a staging site but want to use images from your production site
  • Solution: Set custom domain to your production domain (e.g., www.yoursite.com)
  • Result: Staging site loads images from production without duplicating files

Local Development

  • Problem: Your local environment doesn't have all the media files
  • Solution: Set custom domain to your production or staging domain
  • Result: Local site loads images from remote server

CDN Configuration

  • Problem: You want to serve images from a CDN
  • Solution: Set custom domain to your CDN domain (e.g., cdn.example.com)
  • Result: All images load from CDN

For Developers

The plugin hooks into multiple WordPress filters to ensure comprehensive URL replacement:

Filters Used:

  • wp_get_attachment_url - Substitutes domain in attachment URLs
  • wp_get_attachment_image_src - Handles image source arrays
  • wp_calculate_image_srcset - Processes responsive image srcsets
  • the_content - Replaces domains in post/page content

How it works:

// The plugin replaces the site domain with custom domain
$site_url = parse_url(site_url(), PHP_URL_HOST);
$url = str_replace($site_url, $custom_domain, $url);

Domain Sanitization:

  • Removes http:// or https:// protocol
  • Trims whitespace
  • Removes trailing slashes
  • Sanitizes as text field

Requirements

  • WordPress 5.0 or higher
  • PHP 7.0 or higher

Changelog

1.0.0

  • Initial release
  • Domain substitution for attachment URLs
  • Support for responsive images (srcset)
  • Content filtering for embedded images
  • Admin settings page

License

GPL v2 or later