A WordPress plugin that redirects media file URLs to an external URL, perfect for local development environments.
Media Redirect allows you to redirect all media file URLs (images, videos, documents) from your local WordPress installation to an external URL. This is particularly useful when developing locally but need to serve media files from a production or staging server.
The plugin intercepts WordPress media URL generation hooks and automatically replaces local upload URLs with your configured redirect URL.
- 🚀 Easy Configuration - Simple admin settings page
- 🔄 Automatic Redirect - Hooks into WordPress media URL generation
- 📸 Full Media Support - Works with images, srcsets, and attachment metadata
- 🌍 Multilingual - Includes Russian translation (ru_RU)
- ⚙️ Developer Friendly - Clean codebase with modern PHP practices
- WordPress 5.6 or higher
- PHP 8.2 or higher
- Download the plugin files
- Upload the
media-redirectfolder to/wp-content/plugins/directory - Activate the plugin through the 'Plugins' menu in WordPress
- Navigate to Settings → Media Redirect to configure the redirect URL
composer require dmitriko/media-redirect-
Activate the Plugin
- Go to Plugins → Installed Plugins
- Find "Media Redirect" and click "Activate"
-
Configure Redirect URL
- Navigate to Settings → Media Redirect
- Enter the base URL where your media files are hosted (e.g.,
https://example.com) - Click "Save Changes"
-
How It Works
- The plugin automatically replaces local upload URLs with your configured redirect URL
- Works with:
- Attachment URLs (
wp_get_attachment_url) - Image srcsets (
wp_calculate_image_srcset) - Attachment metadata (
wp_prepare_attachment_for_js)
- Attachment URLs (
If you have a local URL like:
http://localhost/wp-content/uploads/2025/01/image.jpg
And configure redirect URL as:
https://production.example.com
The plugin will automatically redirect to:
https://production.example.com/wp-content/uploads/2025/01/image.jpg
- Node.js and npm
- Composer
- PHP 8.2+
# Install PHP dependencies
composer install
# Install Node dependencies
npm install# Build assets
npm run build
# Create plugin bundle
npm run bundlenpm run build- Build production assetsnpm run start- Start development mode with watchnpm run bundle- Create plugin zip filenpm run lint:js- Lint JavaScript filesnpm run lint:css- Lint CSS files
The plugin uses WordPress i18n standards. To update translations:
# Generate POT file
wp i18n make-pot . languages/media-redirect.pot --domain=media-redirect
# Update existing translation
msgmerge --update languages/media-redirect-ru_RU.po languages/media-redirect.pot
# Compile MO file
msgfmt -o languages/media-redirect-ru_RU.mo languages/media-redirect-ru_RU.pomedia-redirect/
├── assets/ # Compiled assets (CSS, JS)
├── bundle/ # Plugin bundle files
├── inc/ # PHP source files
│ ├── Admin/ # Admin interface classes
│ ├── EventManagement/ # Event subscriber interfaces
│ ├── Generator/ # Template generator
│ ├── Service/ # Service classes
│ ├── Subscriber/ # Event subscribers
│ └── ...
├── languages/ # Translation files
├── src/ # Source assets (SCSS, JS)
├── templates/ # PHP/Twig templates
├── vendor/ # Composer dependencies
├── media-redirect.php # Main plugin file
└── README.md # This file
The plugin follows a clean architecture pattern:
- Event-Driven: Uses WordPress hooks and filters
- Service Layer: Business logic in service classes
- Template System: Twig templating for admin pages
- Dependency Injection: Constructor injection for dependencies
- Plugin URI: https://www.buzzdeveloper.com/media-redirect
- Author: Dmitry Kokorin
- Author URI: https://www.buzzdeveloper.com
GPL v2 or later
Copyright (c) 2025 Dmitry Kokorin
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
- Initial release
- Basic media redirect functionality
- Admin settings page
- Russian translation support