Assign Categories to Media Files

On WordPress you can upload numerous types of files to your "Media" section. Besides attaching those files with your posts, you can upload files and assign any registered taxonomy terms, just like the way you would assign categories to your posts.

By default WP does not provide such feature, however there are functions that will you to do exactly what I just did. This could be particularly very useful if you want to organize your files by category. Here is the snippet.

// add categories to attachments 
function ib_add_categories_to_attachments() {
   register_taxonomy_for_object_type('category','attachment'); }  

Like always, simply copy this snippet and paste it on your current theme's functions.php page and update it. You are all set. You should see the "categories" menu item underneath "Media" menu.

Note: Let's not forget that we are using an already registered (for Posts) taxonomy (category) here. You can achieve the same result simply by registering a custom taxonomy for your "attachment" post type just in case if you do not want to touch your default post "category" taxonomy.

Got questions? Feel free to use the comment section below.


Commenting is disabled.