Register a Custom Taxonomy
Registers a reusable hierarchical custom taxonomy and attaches it to posts and a custom post type, with REST API support.
PHPby SnipCraft
php
<?php
add_action( 'init', 'scseed_register_topic_taxonomy' );
if ( ! function_exists( 'scseed_register_topic_taxonomy' ) ) {
function scseed_register_topic_taxonomy() {
$labels = array(
'name' => 'Topics',
'singular_name' => 'Topic',
'search_items' => 'Search Topics',
'all_items' => 'All Topics',
'parent_item' => 'Parent Topic',
'parent_item_colon' => 'Parent Topic:',
'edit_item' => 'Edit Topic',
'update_item' => 'Update Topic',
'add_new_item' => 'Add New Topic',
'new_item_name' => 'New Topic Name',
'menu_name' => 'Topics',
);
register_taxonomy( 'topic', array( 'post' ), array(
'labels' => $labels,
'hierarchical' => true,
'public' => true,
'rewrite' => array( 'slug' => 'topic' ),
'show_admin_column' => true,
'show_in_rest' => true,
) );
}
}#cpt#custom-taxonomy#register-taxonomy#taxonomy