Change slug of [Custom Taxonomy] on fronted

Change slug of [Custom Taxonomy] on fronted

This is very curious code as you we end up creating taxonomies like “product-cat” or “product_cat” so following code come to rescue earlier the URL was

http://34.230.181.212/sr/product_cat/flans/

after using code above it became

http://34.230.181.212/sr/product-category/flans/
function space_change_custom_taxonomy_slug_args( $taxonomy, $object_type, $args ){
        if( 'product_cat' == $taxonomy ){ 
            remove_action( current_action(), __FUNCTION__ );
            $args['rewrite'] = array( 'slug' => 'product-category' );
        register_taxonomy( $taxonomy, $object_type, $args );
        }
}
add_action( 'registered_taxonomy', 'space_change_custom_taxonomy_slug_args', 10, 3 );

screen18

Leave a Reply

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