Created
February 12, 2019 16:11
-
-
Save yuriitaran/aa971217fe97f3efb60b829ae0241bdd to your computer and use it in GitHub Desktop.
Wordpress SVG support
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
/* | |
* Add SVG to allowed file uploads | |
*/ | |
add_filter( 'upload_mimes', function ( $mimes = array() ) { | |
// allow SVG file upload | |
$mimes['svg'] = 'image/svg+xml'; | |
$mimes['svgz'] = 'image/svg+xml'; | |
return $mimes; | |
}); | |
/** | |
* ADD ABILITY TO VIEW THUMBNAILS IN WP 4.0+ | |
*/ | |
add_action('admin_init', function () { | |
ob_start(); | |
add_action('shutdown', function () { | |
$final = ''; | |
$ob_levels = count(ob_get_level()); | |
for ($i = 0; $i < $ob_levels; $i++) { | |
$final .= ob_get_clean(); | |
} | |
echo apply_filters('final_output', $final); | |
}, 0); | |
add_filter('final_output', function ($content) { | |
$content = str_replace('<# } else if ( \'image\' === data.type && data.sizes && data.sizes.full ) { #>', '<# } else if ( \'svg+xml\' === data.subtype ) { #> | |
<img class="details-image" src="{{ data.url }}" draggable="false" /> | |
<# } else if ( \'image\' === data.type && data.sizes && data.sizes.full ) { #>', | |
$content); | |
$content = str_replace('<# } else if ( \'image\' === data.type && data.sizes ) { #>', '<# } else if ( \'svg+xml\' === data.subtype ) { #> | |
<div class="centered"> | |
<img src="{{ data.url }}" class="thumbnail" draggable="false" /> | |
</div> | |
<# } else if ( \'image\' === data.type && data.sizes ) { #>', | |
$content); | |
return $content; | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment