By default, the WordPress media library allows filtering only by three types: images, audio, and video. However, for some content-heavy websites—especially those relying on downloadable files like PDFs—this limitation can be restrictive.
To enhance usability, we can extend the media manager by using the built-in post_mime_types filter to include additional file types such as PDFs. Here’s how to implement it.
The following code snippet adds a PDF filter option to the WordPress media library interface:
function modify_post_mime_types( $post_mime_types ) {
// Select MIME type: application/pdf
// Define label values
$post_mime_types['application/pdf'] = array(
__( 'PDFs' ),
__( 'Manage PDFs' ),
_n_noop( 'PDF (%s)', 'PDFs (%s)' )
);
return $post_mime_types;
}
add_filter( 'post_mime_types', 'modify_post_mime_types' );
Once this code is added, the filter option for PDFs will appear in the media library—provided that at least one PDF file exists in the library.
This method is not limited to PDFs. You can use the same approach to add filters for any file type supported by WordPress. The full list of allowed MIME types is defined in the get_allowed_mime_types() function, located in wp-includes/functions.php.
Here are a few example mappings of file extensions to MIME types:
'pdf' => 'application/pdf',
'swf' => 'application/x-shockwave-flash',
'mov|qt' => 'video/quicktime',
'flv' => 'video/x-flv',
'js' => 'application/javascript',
'avi' => 'video/avi',
'divx' => 'video/divx',
For instance, to support Flash files, use the slug application/x-shockwave-flash.
With just a few lines of code, you can significantly extend the functionality of the WordPress media manager. Whether you're adding support for PDFs, specific video formats, or other custom file types, this method provides a lightweight and effective solution tailored to your project's needs.