SVG (Scalable Vector Graphics) files are a popular format for web designers and developers as they provide high-quality, scalable graphics that adapt well to different screen sizes. However, by default, WordPress restricts the upload of SVG files due to security concerns. If you need to enable SVG file support in your WordPress website, there are several methods you can follow. In this article, we will explore two methods of enabling SVG file support in WordPress.
Method 1: Using a Plugin
One of the easiest ways to enable SVG file support in WordPress is by using a dedicated plugin. The “Safe SVG” plugin is a popular choice as it not only allows you to upload SVG files but also ensures that the code within the SVG files is secure. Here’s how to use this plugin:
- Log in to your WordPress admin dashboard.
- Navigate to “Plugins” in the left-hand menu and click on “Add New.”
- In the search bar, type Safe SVG and press Enter.
- Locate the Safe SVG plugin and click on the “Install Now” button.
- After installation, click on the “Activate” button to activate the plugin.
- Once activated, you can go to “Settings” > Safe SVG to configure the plugin’s settings.
- In the plugin settings, you can choose to enable SVG support for specific user roles, configure allowed SVG MIME types, and set security options for the uploaded SVG files.
- Save the settings, and now you should be able to upload SVG files using the WordPress media uploader.
Method 2: Editing WordPress Functions.php File
If you prefer a manual approach without relying on plugins, you can enable SVG file support by adding code to the functions.php file of your WordPress theme. Here’s how:
- Login to cPanel and go to File Manager.
- Navigate to public_html -> wp-includes. Scroll down until you locate functions.php.
- Find the functions.php file within your theme’s directory and download a backup copy for safety.
- Open the functions.php file in a text editor.
- Add the following code at the end of the file:
function add_file_types_to_uploads($file_types){
$new_filetypes = array();
$new_filetypes['svg'] = 'image/svg+xml';
$file_types = array_merge($file_types, $new_filetypes );
return $file_types;
}
add_filter('upload_mimes', 'add_file_types_to_uploads');
- Save the changes and upload the modified functions.php file back to your WordPress theme directory.
Conclusion
Enabling SVG file support in WordPress allows you to take advantage of this versatile vector graphics format for your website. Whether you choose to use a plugin or edit the functions.php file, following any of these methods will enable you to upload SVG files and enhance your design capabilities within the WordPress platform. Remember to exercise caution when working with SVG files and ensure they come from trusted sources to maintain the security of your website.