Proper Way To Enable SVG Option in WordPress

In WordPress, by default SVG option is disabled due to security reasons. Apart from that, well known all the images are supports in WordPress Media like .png, .jpg, .jpeg, and .gif. In the latest trend, everyone loves Scalable Vector Graphics (SVG) because of lite weight with high resolution.
If you try to upload the SVG image and you get an error message like Sorry, this file type is not permitted for security reasons? then to solve this issue you need to use custom code in your functions.php and wp-config.php file. Use the below code to enable the SVG option on the WordPress website.
Use the below code in your functions.php to enable media access from the SVG file select.
1 2 3 4 5 6 7 |
function enable_svg( $allowed ) { if ( !current_user_can( 'manage_options' ) ) return $allowed; $allowed['svg'] = 'image/svg+xml'; return $allowed; } add_filter( 'upload_mimes', 'enable_svg'); |
Define the below code in your wp-config.php to allow access for SVG file upload to your media folder.
1 |
define(‘ALLOW_UNFILTERED_UPLOADS’, true); |
Note: By allowing unfiltered uploads maybe cause a security problem.
Output for Uploaded SVG file without plugin
Enable SVG File Option Using the WordPress Plugin
An easy way to enable the SVG file option is plugins with the one-click installation of SVG plugin you can enable and upload the SVG files. The only disadvantage, this may increase the extra weight of your website.
Recommended below SVG Support plugin, this helps with the one-click installation to activate the SVG file option.
Conclusion: I hope anyone this option will help you to solve this SVG file support problem for your WordPress website. If you are newer to WordPress, you can use the plugin but if your developer better you can use the custom code. If you loved this article share it with your friends.
Scalable Vector GraphicsSVGWithout Pluginwordpress
Mraj
Creative Designer & Developer specialist by the spirit and a loving blogger by thoughts. If you have any questions let me drop an email with the article name to the following email id: [email protected]