Skip to content

Instantly share code, notes, and snippets.

@terrytsang
Last active September 9, 2022 14:33
Show Gist options
  • Save terrytsang/68614959e1efccc0bc9419b0641ddd2e to your computer and use it in GitHub Desktop.
Save terrytsang/68614959e1efccc0bc9419b0641ddd2e to your computer and use it in GitHub Desktop.
Allow WordPress admin to upload SVG media file
<?php
//below code snippet is to be added to WordPress theme functions.php file
//enable SVG upload
function tt_enable_svg_upload( $mimes ) {
//Only admin can upload SVG file
if ( !current_user_can( 'administrator' ) ) {
return $mimes;
}
$mimes['svg'] = 'image/svg+xml';
$mimes['svgz'] = 'image/svg+xml';
return $mimes;
}
add_filter('upload_mimes', 'tt_enable_svg_upload');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment