Created
May 6, 2020 09:42
-
-
Save nfsarmento/c9a9f2e2aa4429f79dd1365f8b004ccf to your computer and use it in GitHub Desktop.
Add SVG support on WordPress
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 support | |
* | |
*/ | |
add_filter( 'wp_check_filetype_and_ext', function( $data, $file, $filename, $mimes) { | |
global $wp_version; | |
if( $wp_version == '4.7' || ( (float) $wp_version < 4.7 ) ) { | |
return $data; | |
} | |
$filetype = wp_check_filetype( $filename, $mimes ); | |
return [ | |
'ext' => $filetype['ext'], | |
'type' => $filetype['type'], | |
'proper_filename' => $data['proper_filename'] | |
]; | |
}, 10, 4 ); | |
function ns_mime_types( $mimes ){ | |
$mimes['svg'] = 'image/svg+xml'; | |
return $mimes; | |
} | |
add_filter( 'upload_mimes', 'ns_mime_types' ); | |
function ns_fix_svg() { | |
echo '<style type="text/css">.attachment-266x266, .thumbnail img { width: 100% !important; height: auto !important;} </style>'; | |
} | |
add_action( 'admin_head', 'ns_fix_svg' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment