How To Categorize Media Attachments In WordPress

Have you ever had to dig through hundreds of media files you’ve uploaded in WordPress to find one particular image or video? Wouldn’t it be nice if you could only categorize them to make locating them easier? Sadly, assigning categories to any of your uploaded media isn’t one of the features that are included in WordPress’ Media Editing screen. But then what’s stopping us from creating one?

In one of Rachel McCollin’s articles in WP Tuts+, she shows us a way to add such a feature simply by adding some simple code to your theme functions file (or to a plugin). For starters, there are a few things you’re going to need in order to accomplish this. These are:

  • A development installation of WordPress.
  • An access to your theme’s function file or if you prefer creating a plugin, an FTP access to the server.
  • A text editor.

Once you’re certain you have all these then you can proceed with caution.

The first will require you to open your functions file (or create a plugin file) and add the following code to it which contains the register_taxonomy_for_object_type() function:

function wptp_add_categories_to_attachments() {
 register_taxonomy_for_object_type( 'category', 'attachment' );
}
add_action( 'init' , 'wptp_add_categories_to_attachments' );     

Save the file and refresh the Media Editing screen. If done correctly, you should then see a “Categories” column (see below image). And that’s it! You’re done.


Image source: wp.tutsplus

Aside from adding categories to your media attachments, Rachel also teaches you how to apply tags and custom taxonomies. You can read and find out how it’s all done right here.

Related Posts

Liveblog Add-On Adds Rich Text Editing

Simple Chat Plugin

EWWW Image Optimizer

Twitter Cards PHP 1.1

Leave a Reply









CommentLuv Enabled