Enable SVG Support in WordPress

Are you going to use SVG image file into your WordPress site?
By default, WordPress does not allow you to upload the SVG image into your WordPress media, mainly due to security concerns. By default WordPress allows you to upload only image (jpg, jpeg, gif, png etc), audio and video file formats, but SVG image format not allow to use. In today article, I will show you how to easily Enable SVG Support in WordPress.

Check SVG support enable or not in your wordpress

To check your SVG support enable or not for your wordpress setup simply go to Wp-admin > Media and try to upload SVG type image (Image with extension .svg). if SVG support enable than your browse image will be uploaded successfully to your WordPress Media. and if SVG support not enable than you will get error message : Sorry, this file type is not permitted for security reasons.

1 : Add below script for Enable SVG support

add below script in active theme functions.php file


//add SVG to allowed file uploads
function add_file_types_to_uploads($file_types){
     $new_filetypes = array();
     $new_filetypes['svg'] = 'image/svg';
     $file_types = array_merge($file_types, $new_filetypes );
     return $file_types; 
} 
add_action('upload_mimes', 'add_file_types_to_uploads');

If above script not work for your wordpress website try with following script.


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 );

function cc_mime_types( $mimes ){
  $mimes['svg'] = 'image/svg+xml';
  return $mimes;
}
add_filter( 'upload_mimes', 'cc_mime_types' );
function fix_svg_support() {
  echo '



'; } add_action( 'admin_head', 'fix_svg_support' );

Leave a Comment

Scroll to Top