Site icon Learn Web Development & Programming, Artificial Intelligence, WordPress, Shopify Articles

How to remove product-category slug in WooCommerce?

remove product-category slug in WooCommerce

I was trying to figure out how to remove product category slug in WooCommerce (eg: remove /product-category/ ) from my URLs category and I just couldn’t seem to remove it.

For eg: https://tistook.com/product-category/frock

I just wanted to be https://tistook.com/frock

Finally, I got a quick solution to do this task.

It works for me, and it might work for you.

If you find a bug, please let me know on mail: info@tutorialswebsite.com.

How to remove product category slug in woocommerce without plugin.

You have to follow few steps and setup the rules to do this task. The code is experimental and it is better to avoid using it at production sites. This is exactly what you need to remove the slug from the category pages.

Step-1: Change product category base field of the permalinks page

Enter a “.” in the product category base field of the permalinks page.  This will help to generate the urls around the site like we want.

Step-2: Be sure you don’t have any page, post with the same name (slug)

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.

Step-3: Copy and Paste below code:

You have to copy and paste below code in functions.php file of your current theme folder:

Feel free to test the code and let me know if it’s not working on any particular case. I only tried with two levels of category and pagination, nothing else.

Are you want to get implementation help, or modify or extend the functionality of this script? Submit a paid service request

Also Read: How to remove the Password Strength Meter from WooCommerce on the checkout page

Conclusion:

Technically we filter every request and check If we have any product category with that name, and if we do, we simply set the vars of the request as if we were looking at the category list. It always happens before executing the main sql queries. so this shouldn’t be a waste of resources. It works with page cache plugins and I think that if you use a persistent cache, the code could be modified to make the most of it.

Exit mobile version