Skip to content

Instantly share code, notes, and snippets.

@shelleyhoward
Created February 4, 2014 16:37
Show Gist options
  • Save shelleyhoward/8807308 to your computer and use it in GitHub Desktop.
Save shelleyhoward/8807308 to your computer and use it in GitHub Desktop.
Adds custom categories and tags to media attachemnts
<?php
/*
Plugin Name: Custom Media Categories and Tags
Description: Plugin adds custom categories and tags to media attachemnts
Version: 1.0
Author: Shelley Howard
Author URI: http://shelleyhoward.com
*/
// register new taxonomies which appliy 'Media Category' and 'Media Tag' to attachments
function sh_create_media_taxonomies() {
$labels_cat = array(
'name' => 'Media Categories',
'singular_name' => 'Media Category',
'search_items' => 'Search Media Categories',
'all_items' => 'All Media Categories',
'parent_item' => 'Parent Media Category',
'parent_item_colon' => 'Parent Media Category:',
'edit_item' => 'Edit Media Category',
'update_item' => 'Update Media Category',
'add_new_item' => 'Add New Media Category',
'new_item_name' => 'New Media Category Name',
'menu_name' => 'Media Category',
);
$args_cat = array(
'labels' => $labels_cat,
'hierarchical' => true,
'query_var' => 'true',
'rewrite' => 'true',
'show_admin_column' => 'true'
);
$labels_tag = array(
'name' => 'Media Tags',
'singular_name' => 'Media Tag',
'search_items' => 'Search Media Tags',
'all_items' => 'All Media Tags',
'parent_item' => 'Parent Media Tag',
'parent_item_colon' => 'Parent Media Tag:',
'edit_item' => 'Edit Media Tag',
'update_item' => 'Update Media Tag',
'add_new_item' => 'Add New Media Tag',
'new_item_name' => 'New Media Tag Name',
'menu_name' => 'Media Tag',
);
$args_tag = array(
'labels' => $labels_tag,
'hierarchical' => false,
'query_var' => 'true',
'rewrite' => 'true',
'show_admin_column' => 'true'
);
register_taxonomy( 'media_cat', 'attachment', $args_cat );
register_taxonomy( 'media_tag', 'attachment', $args_tag );
}
add_action( 'init', 'sh_create_media_taxonomies' );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment