pierrebalian of Rocket55 Web Team
1/31/2017 - 8:23 PM

Add SVG support to media uploader - new method post 4.7!!!! Changes made to wp core in version 4.7 breaks the old method of adding svg supp

Add SVG support to media uploader - new method post 4.7!!!!

Changes made to wp core in version 4.7 breaks the old method of adding svg support. This code is the new method.

/* add svg support to media manager */

function bodhi_svgs_disable_real_mime_check( $data, $file, $filename, $mimes ) {
	$wp_filetype = wp_check_filetype( $filename, $mimes );

	$ext = $wp_filetype['ext'];
	$type = $wp_filetype['type'];
	$proper_filename = $data['proper_filename'];

	return compact( 'ext', 'type', 'proper_filename' );
}
add_filter( 'wp_check_filetype_and_ext', 'bodhi_svgs_disable_real_mime_check', 10, 4 );

function 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', 'add_svg_to_upload_mimes', 10, 1 );