Yeah yeah! We understood. You came here because you face the most common problem once you tried to upload an SVG file to your WordPress media library.

Fortunately we have found a workaround for this.

2021 fix for the error “Sorry, This File Type Is Not Permitted for Security Reasons” Error in WordPress

First Things First

Our workaround is a little bit “dirty” and you need to have access to your theme’s code. If you haven’t activate yet a child theme is strongly recommended to do it in order to follow this process. If you don’t know what a child theme is you can take a look in our Glossary.

The Code Part

/**
 * Add SVGs to the list of allowed mime types.
 * 
 * @param array $upload_mimes The existing allowed mime types.
 * 
 * @return array The enhanced allowed mime types.
 */
function bmwp_admin_add_svg_to_upload_mimes( $upload_mimes ) {

    $file_types = array();
    $file_types['svg'] = 'image/svg+xml';
    $upload_mimes = array_merge( $file_types, $upload_mimes );
    return $upload_mimes;

}

add_filter('upload_mimes', 'bmwp_admin_add_svg_to_upload_mimes');

The “hack” part

If you have installed the above code and you have tried to upload an SVG image you should see again the same error message. In order to get rid of this message our recommended way to fix this is to edit manually all your SVG files and add to the very beginning of the file the following line of code:

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

Alternatively if you don’t want to edit your SVG files directly you can use the SVG Sanitizer Test site in order to help you. Just copy and paste your SVG code inside the textarea fields.

Voila! Your SVG images are now ready to be uploaded to your WordPress media library. Enjoy! 🙂

Have you found a better way to upload SVG images in your media library? Please let us know in the comments below and we will keep this article updated in order to help as many people as we can.

WordPress Support Services

Do you need a super fast and optimized website like ours?
We do things different at BakeMyWP!

Get a Free Quote

Leave a Reply

Your email address will not be published. Required fields are marked *