How to enable category and tags for WordPress media attachments

By default, WordPress doesn’t allow users to use categories and tags with WordPress media library attachments. But you can easily enable category and tags support for WordPress attachments.

Useful Read: Add URL Column To WordPress Media Library

All you need to do is copy the following code and paste it inside your functions.php file

//enable category and tags for WordPress media attachments
add_action( 'init', 'fb_attachment_taxonomies' );
function fb_attachment_taxonomies() {
 
    $taxonomies = array( 'category', 'post_tag' ); // add the 2 tax to ...
    foreach ( $taxonomies as $tax ) {
        register_taxonomy_for_object_type( $tax, 'attachment' ); // add to post type attachment
    }
}

 

How to Assign Medias to Tags and Categories in WordPress

How to Assign Medias to Tags and Categories in WordPress

6 Comments

  1. Hey this looks cool! Will share this! Also is there any chance you give an example of when something like this might be useful? I’d never had to make something where the media library images needed taxonomy. Thanks! 🙂

    Reply

Leave a Comment.