copy Copy chevron-down
WooCommerce- How to remove product & product-category from urls? (ok) https://stackoverflow.com/questions/43447175/woocommerce-how-to-remove-product-product-category-from-urls
Copy // Remove slug product-category
add_filter ( 'request' , function ( $vars ) {
global $wpdb;
if ( ! empty ( $vars[ 'pagename' ] ) || ! empty ( $vars[ 'category_name' ] ) || ! empty ( $vars[ 'name' ] ) || ! empty ( $vars[ 'attachment' ] ) ) {
$slug = ! empty ( $vars[ 'pagename' ] ) ? $vars[ 'pagename' ] : ( ! empty ( $vars[ 'name' ] ) ? $vars[ 'name' ] : ( ! empty ( $vars[ 'category_name' ] ) ? $vars[ 'category_name' ] : $vars[ 'attachment' ] ) );
$exists = $wpdb -> get_var ( $wpdb -> prepare ( " SELECT t.term_id FROM $wpdb -> terms t LEFT JOIN $wpdb -> term_taxonomy tt ON tt.term_id = t.term_id WHERE tt.taxonomy = 'product_cat' AND t.slug = %s" , array( $slug ) )) ;
if ( $exists ){
$old_vars = $vars;
$vars = array( 'product_cat' => $slug );
if ( ! empty ( $old_vars[ 'paged' ] ) || ! empty ( $old_vars[ 'page' ] ) ) $vars[ 'paged' ] = ! empty ( $old_vars[ 'paged' ] ) ? $old_vars[ 'paged' ] : $old_vars[ 'page' ];
if ( ! empty ( $old_vars[ 'orderby' ] ) ) $vars[ 'orderby' ] = $old_vars[ 'orderby' ];
if ( ! empty ( $old_vars[ 'order' ] ) ) $vars[ 'order' ] = $old_vars[ 'order' ];
}
}
return $vars;
} ) ; Ask Questionarrow-up-right Asked 5 years, 6 months agoModified 1 year, 1 month agoarrow-up-right Viewed 78k times9
I'm using WooCommerce on a WordPress and it adds product & product-category to the
URLs.
http://dev.unwaveringmedia.com/8dim/product-category/all-party-supplies/arrow-up-right http://dev.unwaveringmedia.com/8dim/product/14-snowman-serving-tray/arrow-up-right
I need to remove 'product' & 'product-category' from the URLs. Is there any way to modify the permalinks and remove them?
Sharearrow-up-right Editarrow-up-right FollowFlagedited Sep 7, 2020 at 6:55arrow-up-right arrow-up-right General Grievancearrow-up-right 4,3312424 gold badges2828 silver badges4343 bronze badgesasked Apr 17, 2017 at 7:30arrow-up-right Bhagya Shreearrow-up-right 9111 gold badge11 silver badge33 bronze badges
you should use of woocommerce seo perfect plugin because it's good for seo and create best url for you I use most way to remove category but I saw there are dot in canonical so i decided to use this plugin cheers – amharrow-up-right Sep 6, 2020 at 14:05arrow-up-right
Add a commentarrow-up-right
Sorted by: Highest score (default) Trending (recent votes count more) Date modified (newest first) Date created (oldest first) 23
Yes. But Please read this article first https://docs.woocommerce.com/document/removing-product-product-category-or-shop-from-the-urls/arrow-up-right
You can change this by:
you can change the permalinks in Settings > permalink > optional > Product category base= ./ (type ./ in Product category base).
Be sure that you don’t have any page, post or attachment with the same name (slug) as the category page or they will collide and the code won’t work.
`
arrow-up-right
For more info please see https://timersys.com/remove-product-category-slug-woocommerce/arrow-up-right
Sharearrow-up-right Editarrow-up-right FollowFlaganswered May 14, 2017 at 11:21arrow-up-right Shehroz Altafarrow-up-right 60811 gold badge1010 silver badges1616 bronze badges
Add a commentarrow-up-right Report this ad3
Noone mentioned how to remove /product/ so here it goes:
I've added priority since some themes/plugins can conflict with this rule, which happened to me.
Sharearrow-up-right Editarrow-up-right FollowFlaganswered Sep 5, 2021 at 7:13arrow-up-right Goran Jakovljevicarrow-up-right 2,49311 gold badge2626 silver badges2424 bronze badges
Add a commentarrow-up-right 2
It wasn't working with pagination for me. Here is full code that's working.
This will add new rewrite rule that will paginate query.
Sharearrow-up-right Editarrow-up-right FollowFlaganswered Jan 21, 2020 at 15:08arrow-up-right Alexarrow-up-right 2111 bronze badgeAdd a commentarrow-up-right 1
Using Shehroz Altaf's trick does the job just (almost) perfectly.
Adding the following between the $slug and $exists declarations will make it work with sub-categories too.
Sharearrow-up-right Editarrow-up-right FollowFlagedited Mar 19, 2019 at 11:11arrow-up-right arrow-up-right AS Mackayarrow-up-right 2,79399 gold badges1818 silver badges2525 bronze badgesanswered Mar 19, 2019 at 10:52arrow-up-right Manu Garridoarrow-up-right 1144 bronze badgesAdd a commentarrow-up-right 1
You can use the following filter: woocommerce_register_post_type_product
Here is an example if you only want to remove /product/ but keep the category.
Then make sure to flush the permalinks by updating the permalinks in the Admin panel.
Keep in mind you will still see '/product/' in the permalink structure in the Admin Panel Permalinks, but it will not have an affect.
Sharearrow-up-right Editarrow-up-right FollowFlaganswered Oct 2, 2020 at 18:38arrow-up-right ggeddearrow-up-right 54455 silver badges1111 bronze badges
Add a commentarrow-up-right 0
Other solutions all failed for me, after some trial and error I came up with this solution...
Set Product Category Base Permalinks to : shop
Set Custom Base Permalinks to : /shop/%product_cat%/
URLs will then look like
Seems to work fine for pagination and sub categories