Skip to content

Instantly share code, notes, and snippets.

View philbirnie's full-sized avatar

Phil Birnie philbirnie

View GitHub Profile
@RadGH
RadGH / rs_upload_from_url.php
Last active September 24, 2025 00:39
Upload a file from a URL to the WordPress media gallery. Supports images, PDFs, and other file types.
<?php
/**
* This function uploads a file from a URL to the media library, designed to be placed in your own theme or plugin.
* Metadata will be generated and images will generate thumbnails automatically.
*
* HOW TO USE:
* 1. Add the function below to your theme or plugin
* 2. Call the function and provide the URL to an image or other file.
* 3. If successful, the attachment ID will be returned.