For security reasons, WordPress only allows certain file types to be uploaded through the WordPress Admin Dashboard by default. We’ll go over what MIME file types are, which ones WordPress doesn’t restrict, and a few ways to remove the restriction and enable the uploading of JSON files (and any additional types).
Table of Contents
- About MIME File Types and WordPress
- Ways to Upload JSON to WordPress
What are MIME File Types?
A Multipurpose Internet Mail Extensions type is a standard way of data type classification used with web technology, such as browsers, to determine how the file will be handled.
A MIME type is made of two parts – a type and subtype, separated by a ‘/’. Some common MIME types are ‘application/json’ , ‘image/png’, and ‘text/html’.
A use-case example is how the browser would determine by a .png file’s MIME type that it must be handled as an image file type, and not as any other file type, such as audio or video.
MIME File Types WordPress Allows by Default
- .doc, .docx
- .ppt, .pptx, .pps, .ppsx
- .xls, .xlsx
Ways to Upload JSON to WordPress
Below are a few different ways we can tell WordPress to allow JSON uploads:
Allow JSON File Uploads via a Plugin
This is the most straight-forward approach, especially if you don’t want to edit any code.
Here are some recommended plugins that are free and simple to use:
WP Add Mime Types
- After downloading the plugin, go to Settings -> MIME Type Settings
- In the “Add Values” settings, add: json = application/json
- Click the “Save” button
- Check that it has been added to the “List of allowed mime types and file extensions by WordPress“
WP Extra File Types Plugin
WP Media File Type Manager
Edit functions.php or custom plugin file
Using the upload_mimes filter will change the default MIME types list allowed by adding each of your desired file types to it.
In your theme’s function.php file (or custom plugin file), add the following code (lines 7-11):
Note: Usually the MIME type for JSON used here would be ”application/json, but because of a current WordPress core bug it’s being interpreted as ‘text/plain’. Therefore, in the code above we use ‘text/plain’.
WordPress has an ALLOW_UNFILTERED_UPLOADS option that can be enabled in the wp-config.php file. This will allow ALL file types to be uploaded by administrator level users, so it may be a bit overkill to enable it if you want just one specific file type enabled.
In the wp-config.php file, add the following code:
MIME type files have the purpose of giving the browser data information so that it knows what to do with media files. WordPress, by default, allows a limited type of files that can be uploaded and that does not include JSON. To set WordPress to accept JSON files for uploading you can either: use a plugin to change the settings, or edit/add code to the functions.php or wp-config.php files.
Hope this article was helpful to you! 😉