Remove taxonomy name and add .html extension in the custom taxonomy term URL

I just created a custom taxonomy “product category” for the default post type. My taxonomy works perfectly fine. However, the URL for the term is not what I want.

For example, I have a “Light” term in “product category” taxonomy.
The current URL for “Light” page is: http://mywebsite.com/product-category/light/
What I expect is: http://mywebsite.com/light.html

Here is my code for the taxonomy register in function.php

function product_category_register_taxonomy() {

$args = array (
‘label’ => esc_html__( ‘Product Category’, ‘Product Category Taxonomy’ ),
‘labels’ => array(
‘menu_name’ => esc_html__( ‘Product Category’, ‘Product Category Taxonomy’ ),
‘all_items’ => esc_html__( ‘All Product Category’, ‘Product Category Taxonomy’ ),
‘edit_item’ => esc_html__( ‘Edit Product Category’, ‘Product Category Taxonomy’ ),
‘view_item’ => esc_html__( ‘View Product Category’, ‘Product Category Taxonomy’ ),
‘update_item’ => esc_html__( ‘Update Product Category’, ‘Product Category Taxonomy’ ),
‘add_new_item’ => esc_html__( ‘Add new Product Category’, ‘Product Category Taxonomy’ ),
‘new_item_name’ => esc_html__( ‘New Product Category’, ‘Product Category Taxonomy’ ),
‘parent_item’ => esc_html__( ‘Parent Product Category’, ‘Product Category Taxonomy’ ),
‘parent_item_colon’ => esc_html__( ‘Parent Product Category:’, ‘Product Category Taxonomy’ ),
‘search_items’ => esc_html__( ‘Search Product Category’, ‘Product Category Taxonomy’ ),
‘popular_items’ => esc_html__( ‘Popular Product Category’, ‘Product Category Taxonomy’ ),
‘separate_items_with_commas’ => esc_html__( ‘Separate Product Category with commas’, ‘Product Category Taxonomy’ ),
‘add_or_remove_items’ => esc_html__( ‘Add or remove Product Category’, ‘Product Category Taxonomy’ ),
‘choose_from_most_used’ => esc_html__( ‘Choose most used Product Category’, ‘Product Category Taxonomy’ ),
‘not_found’ => esc_html__( ‘No Product Category found’, ‘Product Category Taxonomy’ ),
‘name’ => esc_html__( ‘Product Category’, ‘Product Category Taxonomy’ ),
‘singular_name’ => esc_html__( ‘Product Category’, ‘Product Category Taxonomy’ ),
),
‘public’ => true,
‘show_ui’ => true,
‘show_in_menu’ => true,
‘show_in_nav_menus’ => true,
‘show_tagcloud’ => true,
‘show_in_quick_edit’ => true,
‘show_admin_column’ => false,
‘show_in_rest’ => false,
‘rest_base’ => false,
‘hierarchical’ => true,
‘query_var’ => true,
‘sort’ => false,
‘rewrite’ => array(‘slug’ => ‘product-category’,’with_front’ => true)
);

register_taxonomy( ‘product-category’, array( ‘post’ ), $args );
}
add_action( ‘init’, ‘product_category_register_taxonomy’, 0 );

Read more here:: Remove taxonomy name and add .html extension in the custom taxonomy term URL

Leave a Reply

Your email address will not be published. Required fields are marked *