Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

How to Add and Fix MIME Types in WordPress

· 5 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

WordPress blocks certain file uploads by default, which can be frustrating when you need to upload SVG, WebP, or other uncommon file types. This guide shows you how to add custom MIME types and fix common upload errors by editing your theme's functions.php file or using a plugin.

What You'll Need

  • Access to your WordPress admin dashboard
  • FTP or file manager access to your server (for editing files)
  • A code editor (like Notepad++ or VS Code) if you prefer editing files locally
  • Basic understanding of PHP (for the code snippet method)

Step-by-Step

  1. Identify the MIME type you need. MIME types are standardized identifiers like image/svg+xml for SVG files or video/webm for WebM videos. You can find the correct MIME type by searching online or checking the file's properties on your computer.
  2. Choose your method. You can add MIME types via a plugin (easiest) or by adding a code snippet to your theme's functions.php file (more control). For this guide, we'll focus on the code method, as it's widely used and doesn't require installing extra plugins.
  3. Access your theme's functions.php file. In your WordPress admin, go to Appearance → Theme File Editor. Select functions.php from the list on the right. Alternatively, use FTP or your hosting file manager to open /wp-content/themes/your-theme/functions.php.
  4. Add the filter function. Copy and paste the following code at the very end of the file (before the closing ?> tag if it exists):
function my_custom_mime_types( $mimes ) {
    // New allowed MIME types
    $mimes['svg'] = 'image/svg+xml';
    $mimes['webp'] = 'image/webp';
    $mimes['json'] = 'application/json';
    return $mimes;
}
add_filter( 'upload_mimes', 'my_custom_mime_types' );
  1. Customize the list. Replace the example lines with the MIME types you actually need. The format is $mimes['extension'] = 'mime/type';. You can add as many as you want.
  2. Save the file. Click Update File in the theme editor, or upload the modified file via FTP.
  3. Test the upload. Go to Media → Add New and try uploading a file with the new extension. If it works, you're done.
  4. Fix existing upload errors. If you're getting an error like "Sorry, this file type is not permitted for security reasons," it means the MIME type isn't allowed. Adding it via the code above should fix it. If the error persists, check that the file extension matches the MIME type exactly.

Common Mistakes

  • Using the wrong MIME type. For example, SVG files have the MIME type image/svg+xml, not image/svg. Double-check the correct type.
  • Adding the code to the wrong file. Some users add it to the theme's header.php or style.css. It must go in functions.php.
  • Not clearing cache. If you use a caching plugin, the old MIME list might be cached. Clear all caches after making changes.
  • Overwriting the existing array. If you use $mimes = array(...) instead of $mimes['ext'] = ..., you'll wipe out all default MIME types and break uploads.

Tips

  • Use a child theme. If you edit your main theme's functions.php, your changes will be lost when the theme updates. Use a child theme to keep your customizations.
  • Backup your file. Before editing functions.php, download a copy to your computer. If something breaks, you can restore it.
  • Test on a staging site. If possible, test the changes on a staging copy of your site first to avoid breaking your live site.
  • Use a plugin for complex needs. If you need to allow many file types or want a user-friendly interface, consider plugins like "WP Extra File Types" or "File Upload Types." They handle the code for you.

Troubleshooting

Upload still fails after adding the MIME type. Check that the file extension is correct and that the MIME type string is exactly right. Also, some server configurations (like Nginx) have their own upload restrictions. Contact your hosting provider if the issue persists.

White screen after editing functions.php. This usually means there's a syntax error. Revert the file to your backup, or use FTP to restore the original. Then re-add the code carefully, making sure there are no typos.

MIME type works but file doesn't display correctly. For SVG files, WordPress may not render them in the media library preview. That's normal. The file will still be uploaded and usable.

Changes not taking effect. Clear your browser cache, WordPress cache, and any CDN cache. Also, if you're using a security plugin, it might be blocking the file type. Temporarily disable it to test.

Frequently Asked Questions

Can I add MIME types without editing code?

Yes, you can use plugins like "WP Extra File Types" or "File Upload Types" that provide a settings page to add MIME types without touching code.

Is it safe to allow SVG uploads?

SVG files can contain scripts, which pose a security risk. If you allow SVG uploads, ensure you only upload files from trusted sources, or use a plugin that sanitizes SVG files.

Why does WordPress block certain MIME types by default?

WordPress blocks file types that could be used for malicious purposes, like executable scripts or files that could serve as attack vectors. Allowing them requires you to take responsibility for security.

What is the difference between a file extension and a MIME type?

A file extension is the suffix after the dot (e.g., .jpg), while the MIME type is a standardized identifier (e.g., image/jpeg). WordPress uses MIME types to determine if a file is safe to upload.

Will my changes survive a theme update?

No, if you edit your main theme's functions.php, the changes will be overwritten when you update the theme. Use a child theme or a plugin to make changes persistent.

Can I add MIME types for user uploads on the front end?

Yes, the upload_mimes filter applies to all uploads, including those from front-end forms, as long as the form uses the WordPress media handling functions.