From 19037858b93269f02d7b73cbb54feaffa5aa21af Mon Sep 17 00:00:00 2001 From: Aadil Ayub Date: Mon, 29 Apr 2024 11:07:25 +0500 Subject: [PATCH] enable svg uploads --- functions.php | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/functions.php b/functions.php index d448a1f..83e792e 100644 --- a/functions.php +++ b/functions.php @@ -63,4 +63,41 @@ add_action('init', function () { } }); -/*== END DISABLE COMMENTS ==*/ \ No newline at end of file +/*== END DISABLE COMMENTS ==*/ + +/*== ENABLE SVG UPLOADS ==*/ +// Allow SVG +add_filter( 'wp_check_filetype_and_ext', function($data, $file, $filename, $mimes) { + + global $wp_version; + if ( $wp_version !== '4.7.1' ) { + return $data; + } + + $filetype = wp_check_filetype( $filename, $mimes ); + + return [ + 'ext' => $filetype['ext'], + 'type' => $filetype['type'], + 'proper_filename' => $data['proper_filename'] + ]; + +}, 10, 4 ); + +function cc_mime_types( $mimes ){ + $mimes['svg'] = 'image/svg+xml'; + return $mimes; +} +add_filter( 'upload_mimes', 'cc_mime_types' ); + +function fix_svg() { + echo ''; +} +add_action( 'admin_head', 'fix_svg' ); + +/*== END ENABLE SVG UPLOADS ==*/ \ No newline at end of file