WordPress: How to Add More Upload Categories

Add WordPress Media Categories

Media Category Filters

Many websites upload a whole bunch of different file types to their website(s). This is done so easily through WordPress, that people feel compelled to put anything and everything up.

Great, right? Yes and no. Doing so leaves you with a media folder jumbled with a whole bunch of different file types that have less categorization than one would like.

What if you have a lot of PDF files uploaded with your extensive image collection? No filter exists to show ONLY the PDF files (as of right now) so you have to dig through everything to find what you’re looking for OR use the search function (assuming you even know the file name).

Luckily, adding new filters to the media library drop down is easy.

How easy? For PDF support, just coy and paste the below into your theme’s functions file before the PHP closing tag ?>

function modify_post_mime_types( $post_mime_types ) {
	// select the mime type, here: 'application/pdf'
	// then we define an array with the label values
	$post_mime_types['application/pdf'] = array( __( 'PDFs' ), __( 'Manage PDFs' ), _n_noop( 'PDF <span class="count">(%s)</span>', 'PDFs <span class="count">(%s)</span>' ) );
	// then we return the $post_mime_types variable
	return $post_mime_types;
}
// Add Filter Hook
add_filter( 'post_mime_types', 'modify_post_mime_types' );

This code is from WP Tuts — so thank them for it!

Modify as necessary in order to add support for other extension filtering. The possibilities are endless! Imagine a filter list this extensive:
zip, rar, js, css, bmp, jpg, svg, png, exe (bad!), wav, mp3, wmv, wma, fla, flv, swf, doc, docx, txt, mp4, mov, ppt, pptx, psd, xls, xlsx, ico, msi, etc!

I don’t recommend making it overly bloated though, as then it just gets crowded in there, but that’s up to you.

Edit: Just in case you are curious on how to group certain extensions together in one category, then check out the below example I created. It groups PDF, DOC, and DOCX together.

	$post_mime_types['application/pdf, application/msword, application/vnd.openxmlformats-officedocument.wordprocessingml.document'] = array( __( 'Documents' ), __( 'Manage Documents' ), _n_noop( 'Document <span class="count">(%s)</span>', 'Documents <span class="count">(%s)</span>' ) );

As you can see, all I did was add a coma (delimiter) for $post_mime_Types and added a mime type for DOC and DOCX.

Comments

  1. By RBA

    Reply

    • By Michael Haberle

      Reply

Leave a Reply

Your email address will not be published.