Last active
June 16, 2024 10:55
-
-
Save nextab/1f214bbd119bdb641ae8bc8ae74345e6 to your computer and use it in GitHub Desktop.
Snippet for the functions.php of your WordPress (child) theme to allow .svg as a file format.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#region Allow .svg files | |
function nxt_allow_svg($mimes) { | |
$mimes['svg'] = 'image/svg+xml'; | |
return $mimes; | |
} | |
add_filter('upload_mimes', 'nxt_allow_svg'); | |
function nxt_really_allow_svg($checked, $file, $filename, $mimes){ | |
if(!$checked['type']){ | |
$wp_filetype = wp_check_filetype( $filename, $mimes ); | |
$ext = $wp_filetype['ext']; | |
$type = $wp_filetype['type']; | |
$proper_filename = $filename; | |
if($type && 0 === strpos($type, 'image/') && $ext !== 'svg'){ | |
$ext = $type = false; | |
} | |
$checked = compact('ext','type','proper_filename'); | |
} | |
return $checked; | |
} | |
add_filter('wp_check_filetype_and_ext', 'nxt_really_allow_svg', 10, 4); | |
#endregion Allow .svg files |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment