Enable SVG file upload

7

Last updated

Added

Informations

Put this code in functions.php

Code

// 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 ‘
.attachment-266×266, .thumbnail img {
width: 100% !important;
height: auto !important;
}
‘;
}
add_action( ‘admin_head’, ‘fix_svg’ );

Contribute to this page

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *


// 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' );