Skip to content

Instantly share code, notes, and snippets.

@gagimilicevic
Created April 16, 2020 22:11
Show Gist options
  • Save gagimilicevic/172e05e3b7372d8b9301c02e2aef4bfd to your computer and use it in GitHub Desktop.
Save gagimilicevic/172e05e3b7372d8b9301c02e2aef4bfd to your computer and use it in GitHub Desktop.
Enable SVG support and enable svg upload
/**
* Enable SVG upload.
*/
function dwply_svgs_upload_mimes( $mimes = array() ) {
// allow SVG file upload
$mimes['svg'] = 'image/svg+xml';
$mimes['svgz'] = 'image/svg+xml';
return $mimes;
}
add_filter( 'upload_mimes', 'dwply_svgs_upload_mimes', 99 );
/**
* Check Mime Types
*/
function dwply_svgs_upload_check( $checked, $file, $filename, $mimes ) {
if ( ! $checked['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/' ) && $ext !== 'svg' ) {
$ext = $type = false;
}
$checked = compact( 'ext','type','proper_filename' );
}
return $checked;
}
add_filter( 'wp_check_filetype_and_ext', 'dwply_svgs_upload_check', 10, 4 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment