Upload Custom Mime Types in WordPress (SVG, WebP)

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

Topic mime-types svg uploads Wordpress

Category Web


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

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

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.