Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Enable SVG file upload through WordPress Media Uploader
<?php
/**
* Add the SVG Mime type to the uploader
* @author Alain Schlesser (alain.schlesser@gmail.com)
*
* @param array $mimes list of mime types that are allowed by the
* WordPress uploader
* @return array modified version of the $mimes array
*
* @see https://codex.wordpress.org/Plugin_API/Filter_Reference/upload_mimes
* @see http://www.w3.org/TR/SVG/mimereg.html
*/
function as_svg_mime_type( $mimes ) {
// add official SVG mime type definition to the array of allowed mime types
$mimes['svg'] = 'image/svg+xml';
// return the modified array
return $mimes;
}
add_filter( 'upload_mimes', 'as_svg_mime_type' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.