Is there any permanant way to upload images via FTP to WordPress media library other than the available plugins which don’t really work well most of the time? I would really appreciate if anyone could help me with this. Sorry I don’t know PHP.
Thanks in advance!
You can upload your images to your host, and then use media_sideload_image()
to upload each file. Let’s assume you upload all of your images to a folder named wpse
, in the root of your WordPress installation:
// Set the directory
$dir = ABSPATH .'/wpse';
// Define the file type
$images = glob($directory . "*.jpg");
// Run a loop and upload every file to media library
foreach($images as $image) {
// Upload a single image
media_sideload_image($image,'SOME POST ID HERE');
}
Images must be attached to a post, but you can detach them afterward.