0

I'm redesiging a site for a client using Wordpress and WooCommerce and I need to add .html to all the woocommerce permalinks so they don't lose any SEO ranking when we go live with the site. Does anyone know of a way to achieve this? I've searched far and wide, and cannot find a good answer.

Thanks in advance for any assistance.

  • 1
    Just add .html to your permalink structure in Settings > Permalinks – TheDeadMedic Feb 14 '15 at 12:37
  • tried it, doesn't seem to take. – MTuttle Feb 14 '15 at 13:40
  • Just tested, seems like this only affects posts. – TheDeadMedic Feb 14 '15 at 15:26
  • Yeah, any ideas? – MTuttle Feb 14 '15 at 15:27
  • This needs some investigating... – TheDeadMedic Feb 14 '15 at 15:33
4

This is the simplest way to add .html, which involves overriding the default permastructure:

function wpse_178112_permastruct_html( $post_type, $args ) {
    if ( $post_type === 'product' )
        add_permastruct( $post_type, "{$args->rewrite['slug']}/%$post_type%.html", $args->rewrite );
}

add_action( 'registered_post_type', 'wpse_178112_permastruct_html', 10, 2 );

http://codex.wordpress.org/Function_Reference/add_permastruct

For categories:

function wpse_178112_category_permastruct_html( $taxonomy, $object_type, $args ) {
    if ( $taxonomy === 'product_cat' )
        add_permastruct( $taxonomy, "{$args['rewrite']['slug']}/%$taxonomy%.html", $args['rewrite'] );
}

add_action( 'registered_taxonomy', 'wpse_178112_category_permastruct_html', 10, 3 );
  • 2
    Make sure to, after adding the code, flush your rewrite rules by loading Settings > Permalinks. – TheDeadMedic Feb 16 '15 at 11:15
  • Thanks! That worked! If I wanted to change the product category permalinks, would I use "( $post_type === 'product_category' )" ? – MTuttle Feb 16 '15 at 11:33
  • Not quite. See my revision. I also missed the 3rd argument in my original post ($args->rewrite), so make sure to add that in. – TheDeadMedic Feb 16 '15 at 11:40
  • Its working but adding / at the end of every url : like: /magento.html/ – Shiv Singh Feb 2 '18 at 6:06
  • @ShivSingh Make sure there is no trailing slash for your permalink structure settings e.g. /%postname% not /%postname%/ – TheDeadMedic Feb 2 '18 at 11:21

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