WordPress – Enable SVG Uploads

WordPress - General Functions PHP

Snippet Overview

WordPress – Enable SVG Uploads

This function enables the ability to upload SVG files to the WordPress media library. The code below should be placed within your themes functions.php file. The reason this is disabled by default is because malicious code could be embedded within an SVG file. Please use extreme caution if your site grants users the ability to upload images via the front end.

function upload_svg_files( $allowed ) {
    if ( !current_user_can( 'manage_options' ) )
        return $allowed;
    $allowed['svg'] = 'image/svg+xml';
    return $allowed;
}
add_filter( 'upload_mimes', 'upload_svg_files');
0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply