3

I tried uploading after installing different plugins. Even added a filter to functions.php file.

    function add_svg_to_upload_mimes( $upload_mimes ) { 
    $upload_mimes['svg'] = 'image/svg+xml'; 
    $upload_mimes['svgz'] = 'image/svg+xml'; 
    return $upload_mimes; 
    } 
    add_filter( 'upload_mimes', 'add_svg_to_upload_mimes', 10, 1 );

But still uploading an SVG gives the following error. SVG upload error

  • 1
    Look at the file extension. You’re uploading an XML file, not an SVG. – Jacob Peattie Sep 12 '18 at 9:28
4

This question had me scratching my head. Yeah, how come WordPress doesn't support this natively? And then I found out.

You asked how to upload SVG in WordPress 4.9.8 (the current version at the time of writing). You mention that you "tried uploading after installing different plugins". You don't say which plugins, nor whether they relate to SVG.

As I understand the situation, the safest, most appropriate, answer at this time is to use SVF Safe (a plugin written for this very purpose) by Darrell Doyle. If this plugin doesn't work for you, then I'd suggest that you have a conflict elsewhere, and you should follow the usual procedures for resolving that. Personally, if this plugin didn't work for me then I'd give up on the notion of uploading SVGs.

If you haven't already done so, may I suggest reading "SVG Uploads in WordPress - the inconvenient truth" by Bjorn Johansen and/or "How to Safely Enable WordPress SVG Support - 2 Simple Clicks" by Brian Jackson. At least you should know what you are letting yourself in for.

  • I tried uploading the SVG file with the suggested plugin. It worked fine as expected. And the thumbnail to is visible. Thanks a lot for suggesting this. @Tedinoz – Sarath Sep 14 '18 at 6:15
1
//add SVG to allowed file uploads
function add_file_types_to_uploads($file_types){

    $new_filetypes = array();
    $new_filetypes['svg'] = 'image/svg+xml';
    $file_types = array_merge($file_types, $new_filetypes );

    return $file_types;
}
add_action('upload_mimes', 'add_file_types_to_uploads');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.