Snippets Library

Allow SVG Files Upload

Posted by Editorial Staff

As of my knowledge cutoff in September 2021, WordPress does not natively support SVG file uploads in its media library. SVG (Scalable Vector Graphics) files can potentially pose security risks due to the possibility of containing malicious code or scripts. Therefore, by default, WordPress restricts the upload of SVG files.

However, if you still wish to enable SVG file uploads without using a plugin, you can modify your WordPress installation by adding custom code. Here’s an outline of the steps involved:

  1. Access your WordPress installation files. This can typically be done via FTP or using a file manager in your hosting control panel.
  2. Locate the `functions.php` file of your active theme. It is usually found in the `wp-content/themes/your-theme-name/` directory.
  3. Open the `functions.php` file in a text editor.
  4. Add the following code snippet at the end of the file:
function wpr_allow_svg_upload( $mimes ) {
$mimes['svg'] = 'image/svg+xml';
return $mimes;
add_filter( 'upload_mimes', 'wpr_allow_svg_upload' );
  1. Save the changes and upload the modified functions.php file back to your WordPress installation, overwriting the existing file if necessary.

By adding this code, you are extending the list of allowed file types and enabling WordPress to accept SVG uploads. However, it’s crucial to understand the potential security implications of allowing SVG file uploads. Make sure to use this method only if you fully trust the source and content of the SVG files you plan to upload.

Please note that the steps provided are based on the standard WordPress installation at the time of my knowledge cutoff, and it’s always recommended to have a backup of your site before making any modifications to the core files.

Leave a Reply

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