0

I have a plugin I created to allow for us to add additional image types (webp, svg, etc). For some reason it is failing and will not allow me to add svg.

Could use an extra set of eyes on this one please:

function pmp_custom_upload_mimes($existing_mimes = array()) {
    $existing_mimes['webp'] = 'image/webp';
    $existing_mimes['ico'] = 'image/x-icon';
    $existing_mimes['svg'] = 'image/svg+xml';
    
    return $existing_mimes;
}
add_filter('mime_types', 'pmp_custom_upload_mimes');
2
  • 1
    Note that SVG's are not safe to upload, SVG's are documents not images and are closer to PDFs than JPEGS. You need to add a library or plugin to sanitise them. SVGs can contain javascript, iframes and other HTML tags, as well as embedded media from remote domains. Proceed with extreme caution.
    – Tom J Nowell
    Apr 16, 2021 at 15:53
  • Excellent point. I'm perfectly aware. All SVG will only be uploaded by our devs. They are an XML document essentially.
    – elke_wtf
    Apr 16, 2021 at 16:01

1 Answer 1

2

I have discovered the cause. The SVG document needs to contain the xml declaration in the file:

<?xml version="1.0" encoding="utf-8"?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.