isotropic-2022
Share
Blog
Search
Menu

How To Allow JSON File Uploads In WordPress

By James LePage
 on December 22, 2020
Last modified on January 6th, 2022

How To Allow JSON File Uploads In WordPress

By James LePage
 on December 22, 2020
Last modified on January 6th, 2022

JSON files are a great way of storing data, but WordPress blocks their upload by default. Here's how to allow JSON File Uploads In WordPress.

Saving JSON responses to your model in Scala

We ran into this issue when trying to integrate Lotties into our sites, as they come in .JSON format. For security reasons, WordPress will block them from upload. To fix this, we need to add a new MIMEType for JSON, excluding that filetype from the security rules. Once implemented, you can upload a JSON to your WordPress media library, just as you do with images. Self hosting reduces third party requests and speeds up your site.

Install this code using Advanced Scripts or Code Snippets (simply copy paste) and toggle it on. Then just drag and drop your JSON into the media library.

function cc_mime_types($mimes) { $mimes['json'] = 'application/json'; $mimes['svg'] = 'image/svg+xml'; return $mimes; } add_filter('upload_mimes', 'cc_mime_types');
Code language: PHP (php)

Here's where that code's from: StackOverflow article. This actually allows you to upload both JSON and SVGs.

The is an actual security risk here, so turn it on to upload your files, then toggle it off until you need to add a new JSON to your WordPress site. Also, PLEASE sanitize and scan the files for any issues/malicious elements. JSON security. SVG security.

There's also a Plugin that we've used in the past, which allows you to toggle many different MIME (file) types on your site. If you need a bit more power, check it out:

Subscribe & Share
If you liked this content, subscribe for our monthly roundup of WordPress news, website inspiration, exclusive deals and interesting articles.
Unsubscribe at any time. We do not spam and will never sell or share your email.
Subscribe
Notify of
guest
4 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Solomon
Solomon
1 year ago

Thanks a lot James! Didn't seem to work for me though, added your code via code snippets, and still not going through. Could it be on the server side? I'm hosted via vultr on Cloudways..

Also by the way, great commenting interface.. what plugin are you using for commenting?

Last edited 1 year ago by Solomon
Dan
Dan
1 year ago

Thanks for this, very helpful!

Uditha
Uditha
7 months ago

How to add this code? As a java script file? But not working for me

Article By
James LePage
Contributors/Editors
notloggedin
James LePage is the founder of Isotropic Design, a digital agency that builds WordPress websites. I read, write and design constantly!
We're looking for new authors. Explore Isotropic Jobs.
linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram