Skip to content

Instantly share code, notes, and snippets.

@nfsarmento
Created October 1, 2019 15:26
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 nfsarmento/92741d50659d0546740beab28eb9524f to your computer and use it in GitHub Desktop.
Save nfsarmento/92741d50659d0546740beab28eb9524f to your computer and use it in GitHub Desktop.
Allow SVG on wordpress without plugin
// Allow SVG without plugin
add_filter( 'wp_check_filetype_and_ext', function($data, $file, $filename, $mimes) {
global $wp_version;
if ( $wp_version !== '4.7.1' ) {
return $data;
}
$filetype = wp_check_filetype( $filename, $mimes );
return [
'ext' => $filetype['ext'],
'type' => $filetype['type'],
'proper_filename' => $data['proper_filename']
];
}, 10, 4 );
if ( ! function_exists( 'ns_cc_mime_types' ) ) {
function jc_cc_mime_types( $mimes ){
$mimes['svg'] = 'image/svg+xml';
return $mimes;
}
add_filter( 'upload_mimes', 'ns_cc_mime_types' );
}
if ( ! function_exists( 'ns_fix_svg' ) ) {
function ns_fix_svg() {
echo '<style type="text/css">
.attachment-266x266, .thumbnail img {
width: 100% !important;
height: auto !important;
}
</style>';
}
add_action( 'admin_head', 'jc_fix_svg' );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment