Skip to content

Instantly share code, notes, and snippets.

@namncn
Created February 5, 2021 02:50
Show Gist options
  • Save namncn/667f5830d98123f07509533a686762d4 to your computer and use it in GitHub Desktop.
Save namncn/667f5830d98123f07509533a686762d4 to your computer and use it in GitHub Desktop.
Allow SVG File Uploads In WordPress Media / Enable SVG Support in WordPress
<?php
/**
* 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 pixelplus_mime_types( $mimes ){
$mimes['svg'] = 'image/svg+xml';
return $mimes;
}
add_filter( 'upload_mimes', 'pixelplus_mime_types' );
function pixelplus_fix_svg() {
echo '<style type="text/css">.attachment-266x266, .thumbnail img { width: 100% !important; height: auto !important;} </style>';
}
add_action( 'admin_head', 'pixelplus_fix_svg' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment