Created
March 8, 2014 00:05
-
-
Save benfrain/9422862 to your computer and use it in GitHub Desktop.
Allow SVG upload and preview to Media area of Wordpress (add this to functions.php)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function custom_mtypes( $m ){ | |
$m['svg'] = 'image/svg+xml'; | |
$m['svgz'] = 'image/svg+xml'; | |
return $m; | |
} | |
add_filter( 'upload_mimes', 'custom_mtypes' ); |
I had to change:
$(
to
jQuery(
and fix a little image positioning
but otherwise works great, thanks man!
For WordPress 5.7.2 var urlLabel = element.find('label[data-setting="url"]');
needs to be updated to : var urlLabel = element.find('span[data-setting="url"]');
I found that out the hardway but otherwise thank you very much :)
SitePoint has a similiar description that follows this way of doing it too which I also found very helpful.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@brandlinedigital you would need more code to have the media preview to work (grid view, list view and single view) :
In your theme functions.php file :
the assets/js/svg.js file :
the assets/css/svg.css file :