⬇️ Plugin: Simple File Download with Hidden URL
Adds a shortcode to generate download links for media attachments without revealing the real file URL. The download is streamed via a masked query parameter.
🔧 Shortcode
[media-download media_id="123" texts="Download File" image_url="" class=""]
✅ Supported Attributes
| Attribute | Description |
|---|---|
| media_id | (Required) The attachment ID to download. You can find this in the Media Library (click the item and check the URL). |
| texts | Anchor text for the link (ignored if image_url is set). |
| image_url | URL of an image to use as the link content (replaces texts). Useful for a download icon/button image. |
| class | Optional CSS class for styling the anchor. |
🧪 Examples
Basic text link:
[media-download media_id="123" texts="Download PDF"]
Image as link (icon/button):
[media-download media_id="123" image_url="https://example.com/wp-content/uploads/download-icon.png" class="btn-download"]
Styled link with a custom class:
[media-download media_id="123" texts="Get the ZIP" class="button is-primary"]
🧠 How it works
The shortcode outputs an anchor to a masked URL like /?media_dl=123. On page load, the plugin intercepts requests with that query parameter and streams the file contents to the browser with download headers. The real filesystem path is never exposed in the link HTML.
🔒 Notes
- Only attachment files in your Media Library can be downloaded (uses the attachment ID).
- Default supported Content-Types:
pdf,zip,jpeg/jpg. Others are sent asapplication/force-downloadwithattachmentdisposition. - Make sure there is no output before headers (themes/plugins that echo early can break downloads).