File Extension Cover thumbnail hero image File Extension Cover
March 23, 2021

Add New File Types To WordPress Media Library Without a Plugin (use Functions.php)

I recently wrote a post about how to set up your Sony A7S iii. In that post, I wanted to include a .dat file (file with all the camera’s settings available for download).

Unfortunately, WordPress doesn’t allow you to upload any file type to your media library that you want. You have to specifically add it first. So I included the block of code below into my functions.php file and I was good to go.


function custom_upload_extensions( $existing_mimes ) {
    // Add to the list of mime types here.
    $existing_mimes['dat'] = 'application/dat';
    // Return the array back to the function with our added mime type.
    return $existing_mimes;
}
add_filter( 'mime_types', 'custom_upload_extensions' );

To use, simply add all the mime types you need into the $existing_mimes array. From there you can use custom file extensions on your WordPress site without a plugin! Hope this helps!

Shaun Poore wrote this code himself to allow his blog to serve up non-custom file extensions on WordPress. He's a 15+ year professional software engineer and you can trust that his code is good. Maybe the best even.