By default, WordPress restricts certain file types, including JSON files, from being uploaded to the media library for security reasons. However, if you need to upload JSON files - perhaps for structured data, configuration files, or custom development - you can enable this functionality safely.
This guide provides two beginner-friendly methods to allow JSON uploads in WordPress: using a plugin or manually adding code to your site. Whether you’re a non-technical user or comfortable with a bit of code, we’ve got you covered with step-by-step instructions.
Let’s get started!
Why WordPress Blocks JSON Uploads
WordPress restricts certain file types, like JSON, to prevent potential security risks, such as the execution of malicious scripts. However, JSON files are often safe and widely used for data exchange. By following the methods below, you can enable JSON uploads while maintaining site security.
Note: Always back up your WordPress site before making changes to files or installing plugins. Only upload JSON files from trusted sources to avoid security issues.
Method 1: Enable JSON Uploads Using a Plugin
Using a plugin is the easiest and most beginner-friendly way to enable JSON uploads. The File Upload Types by WPForms plugin allows you to add JSON support without touching any code.
Step 1: Install the File Upload Types by WPForms Plugin
Log in to your WordPress admin dashboard.
Navigate to Plugins > Add New in the left-hand menu.
In the search bar, type File Upload Types by WPForms.
Locate the plugin by “WPForms” and click Install Now.
Once installed, click Activate to enable the plugin.
Step 2: Configure the Plugin to Allow JSON Uploads
Go to Settings > File Upload Types in your WordPress dashboard.
In the Available File Types section, locate JSON (application/json).
Check the box next to JSON to enable JSON file uploads.
Click Save Changes at the bottom of the page.
Step 3: Test JSON Uploads
Navigate to Media > Add New in your WordPress dashboard.
Click Select Files or drag and drop a JSON file (e.g., data.json) into the upload area.
If successful, the JSON file will appear in your media library.
Tip: If the upload fails, double-check that the JSON file type is enabled in the plugin settings or try clearing your site’s cache if you’re using a caching plugin.
Method 2: Enable JSON Uploads Manually (Via Code)
If you prefer more control or don’t want to rely on a plugin, you can enable JSON uploads by adding custom code to your WordPress site. This method involves editing your theme’s functions.php file or creating a custom plugin. Don’t worry - we’ll walk you through each step.
Caution: Editing code can break your site if done incorrectly. Always back up your site and use a child theme to avoid losing changes during theme updates.
Option A: Add Code to functions.php of Your Child Theme
Access Your WordPress Files:
Log in to your hosting account or use an FTP client like FileZilla.
Navigate to your WordPress installation child theme directory (usually public_html/wp-content/themes/your-child-theme/).
Locate the functions.php file in your active child theme’s folder (e.g., your-child-theme/functions.php).
Edit functions.php:
Open functions.php in a text editor via FTP (e.g., Notepad++ or VS Code) or using WordPress' built-in text editor.
Add the following code at the end of the file:
function add_json_upload_support($mimes) {
$mimes['json'] = 'application/json';
return $mimes;
}
add_filter('upload_mimes', 'add_json_upload_support');
Save the file (and upload it back to your server if using FTP if edited using an external editor.
Test the Upload:
Go to Media > Add New in your WordPress dashboard.
Upload a JSON file to confirm it works.
Option B: Add Code Using the Code Snippets Plugin
The Code Snippets plugin provides a user-friendly way to add custom code without editing theme files directly. This is a great option if you want to avoid FTP or file management.
Install the Code Snippets Plugin:
Navigate to Plugins > Add New in your WordPress dashboard.
Search for Code Snippets.
Locate the plugin by “Code Snippets Pro” and click Install Now.
Once installed, click Activate.
Add a New Snippet:
Go to Snippets > Add New in your WordPress dashboard.
Enter a title for your snippet, e.g., “Enable JSON Uploads”.
Copy and paste the following code into the code editor:
function add_json_upload_support($mimes) {
$mimes['json'] = 'application/json';
return $mimes;
}
add_filter('upload_mimes', 'add_json_upload_support');
Set the snippet to Run Everywhere (or select “Only run on site front-end” if you prefer, but “Run Everywhere” is recommended for media uploads).
Click Save Changes and Activate.
Security Best Practices
Verify JSON Files: Only upload JSON files from trusted sources to avoid potential vulnerabilities.
Limit File Size: Consider adding a file size limit for uploads to prevent server overload. You can set this in your hosting control panel or with a plugin like Upload Max File Size.
Keep Backups: Use a plugin like UpdraftPlus to back up your site regularly.
Restrict Access: If JSON files contain sensitive data, restrict access to the media library for non-admin users via plugins like User Role Editor.
Troubleshooting
Upload Still Blocked? Check if a security plugin (e.g., Wordfence) is restricting JSON uploads. Adjust its settings or whitelist the JSON file type.
Code Errors? If your site breaks after editing functions.php, revert the changes via FTP and double-check the code for typos.
Plugin Not Working? Ensure the plugin is activated and the JSON file type is checked in its settings.
Conclusion
Enabling JSON uploads in WordPress is straightforward with either a plugin or a few lines of code. For beginners, the File Upload Types by WPForms plugin is the simplest solution, requiring no coding knowledge.
If you’re comfortable with code, adding a snippet to functions.php or via the Code Snippets plugin offers more flexibility.
Have other file types you need to enable? Check out our guide on enabling SVG and WOFF/WOFF2 uploads in WordPress for similar steps.