I want to have the .html
extension in the custom post type taxonomy urls. My custom post type taxonomy it is called “product_cat
“. I will need something like:
www.mydomain.com/product-category/product-category-name.html
Tried this one, inserting in functions.php
, without success:
add_action('init', 'add_html_ext_to_custom_post_type_taxonomies');
function add_html_ext_to_custom_post_type_taxonomies() {
add_rewrite_rule('^product_cat/([^/]+).html', 'index.php?product_cat=$matches[1]', 'top');
}
Further tries:
Also I’ve used the Custom Post Type Permalink plugin and have played around line 559. Replaced the code from line 559 to line 561 with the next one:
$termlink = str_replace( $wp_home, $wp_home, $termlink );
$str = rtrim( preg_replace("/%[a-z_]*%/","",get_option("permalink_structure")) ,'/');//remove with front
return str_replace($str, "", $termlink.'.html' );
This will return the .html
in the taxonomy view page url, but it gives a 404.
I’ve tested your first attempt with using a rewrite rule it works
but you have _ not – had you noticed this as you give your example as
www.mydomain.com/product-category/product-category-name.html
If its not a mistake it might be you have another rule conflicting with it? and also have you flushed the rules? You could check using the Rewrite Rules Inspector plugin and also you can use it to flush the rules if you haven’t already done so.