WordPress™ allow svg uploads

You can use the following piece of code to allow SVG uploads on WordPress™ especially if you do development on local host using a solution like Studio:

function yourtheme_file_types_to_uploads($file_types){
  if ( ! current_user_can( 'administrator' ) ) {
    return $file_types;
  }
  $new_filetypes = array();
  $new_filetypes['svg'] = 'image/svg+xml';
  $new_filetypes['svgz'] = 'image/svg+xml';
  $file_types = array_merge($file_types, $new_filetypes );
  return $file_types;
}
add_filter('upload_mimes', 'yourtheme_file_types_to_uploads');

Copy and paste the code above in your theme functions.php file.

The other options for you would be to install a dedicated plugin like:

Safe SVG
SVG Support
WP SVG Images

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *