Skip to content

Instantly share code, notes, and snippets.

@schlessera
Last active August 29, 2015 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save schlessera/1eed8503110fb3076e73 to your computer and use it in GitHub Desktop.
Save schlessera/1eed8503110fb3076e73 to your computer and use it in GitHub Desktop.
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