Out of the box, there are some file types supported by WordPress, as well as a method for adding / removing file type support. We will look at both of these below. Starting with the supported file types, we have:
Image
- .jpg
- .jpeg
- .png
- .gif
- .ico
Document
- .pdf (Portable Document Format)
- .psd (Adobe Photoshot)
- .doc, .docx (Microsoft Word)
- .ppt, .pptx, .pps, .ppsx (Microsoft PowerPoint)
- .xls, .xlsx (Excel)
- .odt (OpenDocument)
Video
- .mp4
- .m4v
- .mov
- .wmv
- .avi
- .mpg
- .ogv
- .3gp
- .3g2
Audio
- .mp3
- .m4a
- .ogg
- .wav
Modifying Format Support
There are so many additional formats, some which you might wish to enable support for on your WordPress site. There are plugins available which can help with support, but I prefer to add specific support for just those I wish to add to a specific site. Here's how that code, placed inside the theme's function.php file looks:
function modify_wp_mime_types( $mime_types ) {
// Add mime types (file extension, mime type) $mime_types['svg'] = 'image/svg+xml'; // Add SVG support
return $mime_types;
}
// add_filter( hook, function, priority, arguments ); add_filter( 'upload_mimes', 'modify_wp_mime_types', 1, 1 );
Perhaps you wish to remove support for a mime type, to disallow it from being uploaded to your site. We can do that as well.
function modify_wp_mime_types( $mime_types ) {
// Remove mime types
(file extension only)
unset($mime_types['pdf'] ); // Remove PDF supportreturn $mime_types;
}
// add_filter( hook, function, priority, arguments ); add_filter( 'upload_mimes', 'modify_wp_mime_types', 1, 1 );
As you might have asked or perhaps guessed by now, you can both add new mime type support and remove mime type support using the same function like this:
function modify_wp_mime_types( $mime_types ) {
// Add mime types (file extension, mime type) $mime_types['svg'] = 'image/svg+xml'; // SVG support
// Remove mime types (file extension only) unset($mime_types['pdf'] ); // Remove PDF support
return $mime_types;
}
// add_filter( hook, function, priority, arguments ); add_filter( 'upload_mimes', 'modify_wp_mime_types', 1, 1 );
By hooking into the upload_mimes hook, you can modify the allowable file formats for your WordPress site. As other sites suggest, we could even build this out into its own custom plugin for our site, which can be useful especially if you wish to apply the same settings to multiple sites. Or if you simply wish to have the settings set regardless of what theme you settle on for your site. A sample of how a simple site specific file upload support plugin is available in the Plugin Development training series.