Improve Your Media Library’s Drill-down 

Filed in WordPress

Between this blog and my portfolio site, I deal with a lot of media files. They’re usually images, and, fortunately, WordPress offers a drill-down for this by default. However, I also often upload PDFs and ZIPs, neither of which are supported by default for search narrowing. Although I’m working on a more elegant solution, you can get the code for the first incarnation after the vid.

Go to your Admin Panel, then Appearance -> Editor -> Theme Functions. At the bottom of the file, add this code.

function modify_post_mime_types($post_mime_types) {
	$post_mime_types['application/pdf'] = array(
							__('PDFs'),
							__('Manage PDFs'),
							_n_noop('PDFs (%s)', 'PDFs (%s)')
							);

	$post_mime_types['application/zip'] = array(
							__('Zips'),
							__('Manage Zips'),
							_n_noop('Zips (%s)', 'Zips (%s)')
							);
	return $post_mime_types;
}

add_filter('post_mime_types', 'modify_post_mime_types');

This is what you get.

(Hattip to the WP support forums for the original code).

So, let’s break that code down. application/pdf and application/zip are the mime types of the files I wanted. You could, however, drop in any mime type that you use frequently. After that, you need to replace PDFs/ZIPs with whatever you want to use to denote that file type. For example, if you want a tab for documents.

$post_mime_types['application/doc'] = array(
						__('Docs'),
						__('Manage Docs'),
						_n_noop('Docs (%s)', 'Docs (%s)')
						);

WordPress will also allow a wild-card mime type search. In essence, that’s all the image/video/audio tabs are. The image tab matches image/*, for example. So, you can create a forth option that applies to “application” – unfortunately, pretty much everything that is not audio, video or image falls under that category. That option will result in a list that displays docs, PDFs, archives and anything else that matches application/*.

Feedback

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

About Me


I'm Becky. I write this blog. From time to time, someone else will write this blog. I like WordPress, hiking and puppies.

You can hire me for WordPress or PHP odds n' ends on oDesk.