Skip to content

Allow SVG File Extension Upload in WooCommerce

WooCommerce is a popular e-commerce platform built on top of the WordPress content management system. By default, WooCommerce only supports a limited number of file types for product images, including JPEG, PNG, and GIF. However, there are cases when you may want to use SVG images to represent your products. In this post, we’ll show you how to add support for uploading SVG files in WooCommerce using a custom filter.

The first step is to create a function that adds SVG to the list of supported file types in WordPress. This function will be passed to the upload_mimes filter, which controls the allowed file types for uploading in WordPress.

In this code snippet, the custom_svg_mime_support function takes in the existing list of allowed file types, adds the svg file type to it, and returns the updated list. The add_filter function hooks this function to the upload_mimes filter, so that it’s executed whenever the list of allowed file types is generated.

By adding support for SVG files, you can now upload SVG images to your WooCommerce products and use them to represent your products. This can be especially useful for logos, icons, and other types of graphics that can be represented as SVGs.

In conclusion, adding support for SVG files in WooCommerce is a straightforward process that can be accomplished by using a custom filter. With this simple modification, you can enhance the visual representation of your products and make your online store even more appealing to your customers.


Leave a Reply

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