Allow JSON file uploads in WordPress Media Library

Allow json file uploads in wordpress media library image

Whoa! Check out this fun lil piggy. Just a couple simple lines and you can upload JSON files to your WordPress site! Hotdamn.

What it does…

Allows JSON files to be uploaded in the WordPress Media Library.

How it does it…

Hooks into `upload_mimes` and adds `application/json` as a valid/allowed mime type. I use this set to admin

Download JSON for importing into Code Snippets Pro
Download PHP for adding as a plugin or copying into functions.php

See the code…

<?php

// Allow JSON file uploads in WordPress Media Library
// https://snipsnip.pro/s/91
if (\current_user_can('manage_options')) {
    \add_filter('upload_mimes', function($mime_types){
        $mime_types['json'] = 'application/json'; 
        return $mime_types; 
    },99);
}