# Categories for Media Files

> Lets you assign post categories to images and other attachments to organize the Media Library.

- Type: PHP
- Runs: Run everywhere
- Category: [Media](https://wpide.com/library/category/media/)
- Tags: media, categories, organization
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/categories-for-media/

## Code

```php
add_action( 'init', function () {
    register_taxonomy_for_object_type( 'category', 'attachment' );
}, 20 );
```

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Categories for Media Files" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
