ssaidz

Custom Taxonomy Label for WordPress

Aug 24th, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.16 KB | None | 0 0
  1. //hook into the init action and call create_book_taxonomies when it fires
  2. add_action( 'init', 'create_topics_hierarchical_taxonomy', 0 );
  3.  
  4. //create a custom taxonomy name it topics for your posts
  5.  
  6. function create_topics_hierarchical_taxonomy() {
  7.  
  8. // Add new taxonomy, make it hierarchical like categories
  9. //first do the translations part for GUI
  10.  
  11.   $labels = array(
  12.     'name' => _x( 'Topics', 'taxonomy general name' ),
  13.     'singular_name' => _x( 'Topic', 'taxonomy singular name' ),
  14.     'search_items' =>  __( 'Search Topics' ),
  15.     'all_items' => __( 'All Topics' ),
  16.     'parent_item' => __( 'Parent Topic' ),
  17.     'parent_item_colon' => __( 'Parent Topic:' ),
  18.     'edit_item' => __( 'Edit Topic' ),
  19.     'update_item' => __( 'Update Topic' ),
  20.     'add_new_item' => __( 'Add New Topic' ),
  21.     'new_item_name' => __( 'New Topic Name' ),
  22.     'menu_name' => __( 'Topics' ),
  23.   );  
  24.  
  25. // Now register the taxonomy
  26.  
  27.   register_taxonomy('topics',array('post'), array(
  28.     'hierarchical' => true,
  29.     'labels' => $labels,
  30.     'show_ui' => true,
  31.     'show_admin_column' => true,
  32.     'query_var' => true,
  33.     'rewrite' => array( 'slug' => 'topic' ),
  34.   ));
  35.  
  36. }
Add Comment
Please, Sign In to add comment