Register Taxonomy

Advertisement

Below is the code snippet in which we register a new Taxonomy for the Post.

add_action( 'init', 'prefix_register_taxonomy' );

function prefix_register_taxonomy() {
 
    $labels = array(
        'name'              => _x( 'My Taxonomies', 'taxonomy general name', 'textdomain' ),
        'singular_name'     => _x( 'My Taxonomy', 'taxonomy singular name', 'textdomain' ),
        'search_items'      => __( 'Search My Taxonomies', 'textdomain' ),
        'all_items'         => __( 'All My Taxonomies', 'textdomain' ),
        'view_item'         => __( 'View My Taxonomy', 'textdomain' ),
        'parent_item'       => __( 'Parent My Taxonomy', 'textdomain' ),
        'parent_item_colon' => __( 'Parent My Taxonomy:', 'textdomain' ),
        'edit_item'         => __( 'Edit My Taxonomy', 'textdomain' ),
        'update_item'       => __( 'Update My Taxonomy', 'textdomain' ),
        'add_new_item'      => __( 'Add New My Taxonomy', 'textdomain' ),
        'new_item_name'     => __( 'New My Taxonomy Name', 'textdomain' ),
        'not_found'         => __( 'No My Taxonomies Found', 'textdomain' ),
        'back_to_items'     => __( 'Back to My Taxonomies', 'textdomain' ),
        'menu_name'         => __( 'My Taxonomy', 'textdomain' ),
    );
 
    $args = array(
        'labels'            => $labels,
        'hierarchical'      => true,
        'public'            => true,
        'show_ui'           => true,
        'show_admin_column' => true,
        'query_var'         => true,
        'rewrite'           => array( 'slug' => 'my-taxonomy' ),
        'show_in_rest'      => true,
    );
 
 
    register_taxonomy( 'my-taxonomy', 'post', $args );
 
}

What are you looking for?

%d bloggers like this: