using media_sideload_image with a file from theme directory

Please include the following files before using media_sideload_image() for it to work, require_once(ABSPATH . ‘wp-admin/includes/media.php’); require_once(ABSPATH . ‘wp-admin/includes/file.php’); require_once(ABSPATH . ‘wp-admin/includes/image.php’); Reference, WP Codex: media_sideload_image

How To Get The File Extension Of Images Having Different Extensions In A Directory?

You could send a HEAD request for the allowed resources until you hit a status 200, cache the results (post meta, an option, whatever), and show the best match. The allowed banner sizes and formats are: ‘banner-1544×500.png’, ‘banner-772×250.png’, ‘banner-1544×500.jpg’, ‘banner-772×250.jpg’, The allowed icon sizes and formats: ‘icon.svg’, ‘icon-256×256.jpg’, ‘icon-128×128.png’, Sending a HEAD request can be … Read more

Retain the original name of the image on resize

You can simply use preg_replace() functions to remove -800×667 (or any height) from the image. Like this- $image = generate_filename( NULL, NULL, ‘jpg’); echo preg_replace( ‘/-800x[0-9]{2,4}/’, ”, $image );