A WordPress must-use plugin that replaces local media URLs with production URLs, allowing developers to work in local environments without downloading all media files.
Remote Media Library automatically rewrites URLs pointing to wp-content/uploads on local development environments to point to your production site instead. This eliminates the need to sync gigabytes of media files to your local machine while developing.
- Automatically detects local development environments
- Replaces media URLs in real-time before page output
- Zero configuration after initial setup
- No database tables or stored options
- Skips admin pages to keep WordPress media library functional
- Lightweight with minimal performance impact
- Must-use plugin - always active, cannot be accidentally deactivated
- WordPress 4.0 or higher
- PHP 7.4 or higher
As a must-use plugin, installation is simple:
-
Copy
0000-remote-media-library.phpto your WordPressmu-pluginsdirectory:cp 0000-remote-media-library.php wp-content/mu-plugins/
Or if using a subdirectory structure:
mkdir -p wp-content/mu-plugins/remote-media-library cp 0000-remote-media-library.php wp-content/mu-plugins/remote-media-library/
-
Configure the production URL (see Configuration section below)
Note: Must-use plugins are automatically activated and cannot be deactivated through the WordPress admin interface. They also don't appear in the regular plugins list.
Edit 0000-remote-media-library.php and update the following constants:
const LIVE_URL = 'https://example.com'; // Your production site URL
const LOCAL_URLS = [ '.local', '.test', '.dev', '.box' ]; // Local domain patterns
const PATH_TO_CHECK = '/wp-content/uploads/'; // Upload directory path- LIVE_URL: The full URL of your production site (no trailing slash)
- LOCAL_URLS: Array of strings to detect local environments. The plugin activates if the home URL contains any of these strings.
- PATH_TO_CHECK: The path to your uploads directory (default:
/wp-content/uploads/)
- The plugin checks if the site is running in a local environment by matching the home URL against
LOCAL_URLSpatterns - On the
template_redirecthook, if the site is local and not in admin, output buffering begins - During output buffering, a callback function processes the HTML content
- All instances of your local uploads URL are replaced with the production uploads URL
- The callback also handles escaped versions of URLs (for JSON, etc.)
- The modified HTML is sent to the browser
This plugin is ideal for:
- Development teams working with sites that have large media libraries
- Agencies managing multiple client sites with extensive image galleries
- Developers with limited local storage or bandwidth
- Teams wanting faster local environment setup
- Only works on the frontend (admin is intentionally excluded)
- Requires production site to be publicly accessible
- May have minor performance impact on pages with large HTML output
- Does not handle media uploads from local environments
GPL-2.0+
Andrew Miller @ 84EM https://84em.com
Pull requests welcome.