admin管理员组

文章数量:1295327

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');

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');
Share Improve this question edited Apr 16, 2021 at 15:15 elkefreed asked Apr 16, 2021 at 15:08 elkefreedelkefreed 3851 gold badge5 silver badges16 bronze badges 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 Commented 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. – elkefreed Commented Apr 16, 2021 at 16:01
Add a comment  | 

1 Answer 1

Reset to default 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"?>

本文标签: Upload Custom Mime Types in WordPress (SVGWebP)