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 worked as a professional software developer for 15 years before transitioning into content creation and digital product businesses. Shaun's currently focused on providing as many people as possible with actionable advice and tools they can use to succeed online, without the fluff or BS that too often plagues this industry.