Allow SVG through WordPress Media Uploader
For your functions.php file or a functionality plugin:
function cc_mime_types( $mimes ){
$mimes['svg'] = 'image/svg+xml';
return $mimes;
}
add_filter( 'upload_mimes', 'cc_mime_types' );
Without this, SVG files will be rejected when attempting to upload them through the media uploader.
Thank you!
Thanks alot. I have a Plugin for WordPress with these lines:
_enable_svg_mime_type();
}
private function _enable_svg_mime_type() {
add_filter( ‘upload_mimes’, array( &$this, ‘allow_svg_uploads’ ) );
}
public function allow_svg_uploads( $existing_mime_types = array() ) {
return $this->_add_mime_type( $existing_mime_types );
}
private function _add_mime_type( $mime_types ) {
$mime_types[ 'svg' ] = ‘image/svg+xml’;
return $mime_types;
}
}
if ( class_exists( ‘scalable_vector_graphics’ ) and ! isset( $scalable_vector_graphics ) ) {
$scalable_vector_graphics = new scalable_vector_graphics();
$scalable_vector_graphics->execute();
}
?>
Is this the same or does it more than your function?
Worked like a charm! Just built my first SVG based site with absolutely no image files using WordPress. You’ve been a great help. Thanks so much :)
Works brilliantly for the upload part, however, the SVG displays huge wherever it gets displayed in WordPress admin, is there a way to prevent this?
Using another snippet I found on here, a simple style injection seems to fix the display of SVGs within the admin area, this fixes the display in the media uploader and the featured image area: