Allow SVG upload in WordPress Media Library

WordPress will not allow uploading SVG files even if the necessary mime types are added like this:

function bmwp_add_svg_to_upload_mimes( $upload_mimes ) {

    $upload_mimes['svg']  = 'image/svg+xml';
    $upload_mimes['svgz'] = 'image/svg+xml';

    return $upload_mimes;

}

add_filter( 'upload_mimes',   'bmwp_add_svg_to_upload_mimes' );

if the SVG file does not have the special XML tag in its beginning like this:

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

Alternatively we can use a plugin like Safe SVG from a trusted author like 10up.