Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question
    
Just wondering, why? Is it for SEO? If yes, you should really do a 301 redirect to the proper page. –  David Kryzaniak Jul 26 '13 at 2:41
    
It is just a request from a friend. Don't know his reasons. This must be done dynamically. –  Grávuj Miklós Henrich Jul 28 '13 at 14:24

1 Answer 1

up vote 1 down vote accepted
+50

I've tested your first attempt with using a rewrite rule it works

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');
}

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.

share|improve this answer
    
Thank you for your effort and help. Yeah, I haven't seen the wood because of a tree :) It works now also for me like this: add_rewrite_rule('^product-category/([^/]+)\.html', 'index.php?product_cat=$matches[1]', 'top'); One single issue: subcategories are returning a 404 –  Grávuj Miklós Henrich Jul 29 '13 at 14:15
    
Is there a separate parameter for sub categories or is it just product_cat=subcategory? –  Mark Davidson Jul 29 '13 at 14:20
    
The same parameter also for sub categories, product_cat. –  Grávuj Miklós Henrich Jul 29 '13 at 14:21
    
Can you give me an example of a subcategory your testing with? Might be something to do with that subcategory conflicting with another rule. –  Mark Davidson Jul 29 '13 at 14:48
    
http://www.mydomain.com/product-category/parent-product-category/sub-category.h‌​tml from where product-category is the category base, as it shows also above in the desc. –  Grávuj Miklós Henrich Jul 29 '13 at 15:19

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.