SVG upload does not work

admin2025-01-07  3

I have created an SVG with clickable areas to be used as landing page image, The size of the file is 4 MB. I cannot upload it, Wordpess says there is an error (no specifics). Size seems not to be the problem, other files of this size are uploaded.

I have the SVG Support plugin installed.

I used lnkscape to create it. It looks fine in Edge and does what it is supposed to. I tried all SVG formats that are available in lnkscape but all fail.

I do not use Media Library Assistant.

Where could I start looking what the problem is?

Could the theme I use be the problem (Thefour)?

Bear with me if this is really trivial - I am very new to this.

I have created an SVG with clickable areas to be used as landing page image, The size of the file is 4 MB. I cannot upload it, Wordpess says there is an error (no specifics). Size seems not to be the problem, other files of this size are uploaded.

I have the SVG Support plugin installed.

I used lnkscape to create it. It looks fine in Edge and does what it is supposed to. I tried all SVG formats that are available in lnkscape but all fail.

I do not use Media Library Assistant.

Where could I start looking what the problem is?

Could the theme I use be the problem (Thefour)?

Bear with me if this is really trivial - I am very new to this.

Share Improve this question edited May 17, 2021 at 8:14 Ulrich Sommer asked May 17, 2021 at 6:30 Ulrich SommerUlrich Sommer 12 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

Wordpress doesn't allow to upload SVG files by default.

Add svg file type in allowed file types list

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

Fix for displaying svg files in media library

function wp_fix_svg() {
    echo '<style type="text/css">
        .attachment-266x266, .thumbnail img {
         width: 100% !important;
         height: auto !important;
        }
        </style>';
}
add_action( 'admin_head', 'wp_fix_svg' );

Attempt to determine the real file type of a file

function wp_check_filetype($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']
    ];
}
add_filter( 'wp_check_filetype_and_ext', 'wp_check_filetype', 10, 4 );
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736261173a720.html

最新回复(0)