试着用纯代码的方式来开启wordpress SVG格式图片上传功能。目前看使用Block编辑器图片能正常上传和显示。

function minuo_allow_additional_mime_types($mime_types) {
if ( ! current_user_can( 'administrator' ) ) {
return $mime_types;
}
$mime_types['svg'] = 'image/svg+xml';
$mime_types['svgz'] = 'image/svg+xml';
$mime_types['webp'] = 'image/webp';
$mime_types['ico'] = 'image/vnd.microsoft.icon';
return $mime_types;
}
add_filter('upload_mimes', 'minuo_allow_additional_mime_types');
function minuo_wp_check_filetype_and_ext( $wp_check_filetype_and_ext, $file, $filename, $mimes, $real_mime ) {
if ( ! $wp_check_filetype_and_ext['type'] ) {
$check_filetype = wp_check_filetype( $filename, $mimes );
$ext = $check_filetype['ext'];
$type = $check_filetype['type'];
$proper_filename = $filename;
if ( $type && 0 === strpos( $type, 'image/' ) && 'svg' !== $ext ) {
$ext = false;
$type = false;
}
$wp_check_filetype_and_ext = compact( 'ext', 'type', 'proper_filename' );
}
return $wp_check_filetype_and_ext;
}
add_filter('wp_check_filetype_and_ext', 'minuo_wp_check_filetype_and_ext' , 10, 5);