WordPress allows you to upload various types of files to your media library, such as images, videos, audio, documents, and more. However, there are some file types that are not supported by WordPress by default, such as SVG, PDF, ZIP, etc. This can be a problem if you want to upload these files to your site for different purposes, such as:

  • Displaying vector graphics or icons using SVG
  • Sharing ebooks or reports using PDF
  • Offering downloads or backups using ZIP
  • And more

In this article, we will show you how to add file type upload support in WordPress using two methods: using a plugin or using code.

Method 1: Using a Plugin

The easiest way to add file type upload support in WordPress is to use a plugin. There are many plugins that allow you to do this, but we recommend using WP Extra File Types. This plugin not only lets you enable or disable the existing file types that WordPress supports, but also gives you the option to add new file types that you want to upload to your site.

To use this plugin, follow these steps:

  1. Install and activate the WP Extra File Types plugin from your WordPress dashboard.
  2. Go to Settings > Extra File Types and check the boxes next to the file types that you want to enable or disable.
  3. If you want to add a new file type that is not listed, scroll down to the Add New File Type section and enter the file extension and MIME type of the file type that you want to add. You can find the MIME type of any file type online or use this tool to generate it.
  4. Save your changes and check your media library to see if you can upload the new file types.

Method 2: Using Code

If you prefer to use code instead of a plugin, you can also add file type upload support in WordPress by adding a custom function to your theme’s functions.php file. This method requires some basic coding skills, so make sure you backup your site before making any changes.

To use this method, follow these steps:

  1. Access your site’s files via FTP or your hosting control panel and locate your theme’s functions.php file. You can find it in wp-content/themes/your-theme-name/functions.php.
  2. Open the file in a code editor and add the following code at the end of the file:
<?php

// Add file type upload support in WordPress
function custom_file_types( $types ) {
    // Add new file types that you want to upload
    // You can add as many as you want
    $types['svg'] = 'image/svg+xml'; // Change these values to your desired ones
    $types['pdf'] = 'application/pdf'; // Change these values to your desired ones
    return $types;
}
add_filter( 'upload_mimes', 'custom_file_types' );
  1. Save and upload the file back to your server and check your media library to see if you can upload the new file types.

Conclusion

Adding file type upload support in WordPress can help you enhance the functionality and usability of your site. You can do this easily using a plugin like WP Extra File Types or using code in your functions.php file. We hope this article was helpful for you. If you have any questions or feedback, please let us know in the comments below. Thank you for reading!

Categorized in: