Are you looking for how to add the product’s category to your product page URLs in WooCommerce?
By default, product page URLs include the “/product/” base slug followed by the slug you choose for that particular product page (usually, this slug will be your product’s name/keyword).
For example:
https://example.com/product/product-name
https://example.com/product/red-apples
But maybe you want your product URLs to include the product category that your particular product belongs to:
https://example.com/product/fruits/red-apples
You might also want to remove that “/product/” base slug to produce a shorter URL:
https://example.com/fruits/red-apples
Now, every product page URL will contain only its category followed by the slug you choose for that particular product page.
In this quick and easy to follow tutorial, I’ll show you exactly how you can do this for your WooCommerce shop.
Why Add a Product’s Category to Product Page URLs?
When it comes to your product page URLs, it’s important to ask how the URL adds value for customers and the rest of your store.
Sometimes you might want to include the category in the URL of your product pages.
Consider the following two product page URLs:
https://example.com/gardening-tools/pruning-saw
https://example.com/pruning-saw/
The first product page URL contains its product category in the URL, whereas the second URL only contains the product name.
The potential customer that sees the first URL will immediately know the pruning saw is part of the “gardening tool” category.
As such, they will have a better idea of where they are on your store.
Additionally, they will have a better understanding of your product range, realizing there is a whole section of gardening tools.
And this can be interpreted simply from seeing the URL, even if they weren’t on your site.
Having the category in the URL might also help Google to better understand your page as it relates to the product and its category.
“Navigation is important for search engines
The navigation of a website is important in helping visitors quickly find the content they want. It can also help search engines understand what content the website owner thinks is important.
Although Google’s search results are provided at a page level, Google also likes to have a sense of what role a page plays in the bigger picture of the site.”
For an example, when I searched “gardening tools” in Google, Lee Valley ranked on the first page.
This took me to their “gardening care” category, where I clicked on a pair of gardening saws.
As you can see from the URL below, they are using several folders to create a navigational structure in their product page URL:
https://www.leevalley.com/shop/garden/garden-care/saws/10231-pruning-saw-and-scabbard
This URL shows customers exactly where they are on their site.
They’re inside the “garden” category, inside “garden care” sub-category, inside the “saw” sub-sub-category”, and at the product page for a particular pruning saw.
“Garden” (category)-> “Garden Care” (sub-category)-> “Saw” (sub-sub category)-> “Product”.
Lee Valley has over 10k+ products, so they have a URL structure consisting of more than one product category/folder.
For your own store, you will need to determine whether you believe adding the product category to your product page URLs adds more value compared to not having it.
If so, below is how you can easily this up:
A Cautionary Note on Changing URLs
Before moving on, it’s important to mention that changing the URL structure of your pre-existing URLs can cause problems if not planned correctly.
When you change the URL structure, the URLs of those affected webpages will change.
Search engines will then have to re-index the webpage with the new URL.
With the finnicky, volatile, and competitive nature of search engines, there is no guarantee the rankings for a particular page will return to exactly where it was before.
In other words, it could come back ranking better or worse.
So, if your webpages are already ranking well, it very well might not be worth the risk to change their URLs.
This is why it’s advised that you get your permalinks and URLs right the first time, for the long haul, when you first publish a page.
On the other hand, if your website is new or the URLs to be modified are not ranking, then you won’t have nearly the same dilemma to deal with.
Adding Product Category Name as a Base Slug
By default, WooCommerce forces you to have the “/product/” base slug for all of your product page URLs.
https://example.com/product/product-name
You can rename it from “/product/” to any other term consisting of at least one character.
For example:
https://example.com/p/product-name
Unfortunately, even if you add the product category to your product page URLs, this product base slug must remain.
So, your product page URLs would look like this:
https://example.com/product/product-category-name/product-name
https://example.com/product/fruits/red-apples
Since you want to add the product category name to the product page URL, you probably do not want that “/product/” base slug adding extra length to it.
There is a way we can get around this.
You simply must remove the “/product/” base slug from all of your product page URLs.
While WooCommerce won’t allow this, we can do it a third-party plugin, and at the same time that we add the product’s category to our URLs.
Step 1: Install and Activate Permalinks Manager Plugin
Permalinks Manager is the way you’re going to be able to remove “/product/” base slug from your URLs.
It’s also going to be used to add the product’s category name in its place.
After discovering this plugin, I now use it for all of my online stores.
Permalinks Manager will allow you to easily change the structure of virtually any kind of URL on your site that you want.
First, download, install, and activate Permalinks Manager.
Step 2: Remove Product Slug from Permalinks and Add Product Category
In admin side panel, go to Tools->Permalinks Manager, then click on the “Permastructure” tab.
Scroll down to “WooCommerce” section.
For “Products” field, remove everything from this line and add the following:
%product_cat%/%product%
Next, press “Save Permastructures” button at the bottom of this page.
What this does is:
- Removes the “/product/” base slug from product page URLs
- Adds the product’s category to the URL in its place
- Preserves the product’s slug/name, which comes after the product category in the URL
In other words, it will make your product page URLs look like this:
https://example.com/product-category-name/product-name
https://example.com/fruits/red-apples
However, this new URL structure only applies to all new product URLs that you will create.
You still need to change the URL structure of your pre-existing product URLs.
Step 3: Apply the New URL Structure to Pre-existing Products URLs
With Permalinks Manager, you can easily bulk change all of your pre-existing product URLs to the new URL structure in one go.
Bulk change product URLs
Within Permalinks Manager settings, go to the “Tools” tab then “Regenerate/Reset” link.
You are presented with several options for regenerating URLs.
Here you can bulk change all your product page URLs at once, based on the “permastructure” that you set in Step 2.
In other words, this setting will remove all of the “/product/” base slugs from your pre-existing product page URLs, replacing them with the product’s category.
Here is what to do:
- Make sure Mode is kept at “Regenerate custom permalinks”.
- For “Select post types” you only want “Products” selected
- For “Select post statuses” select all post status types
If everything is set up correctly, press the “Regenerate” button.
Once all the links are regenerated, Permalinks Manager will show you the modified URLs.
As you can see, for my product pages, their URLs have changed from:
https://example.com/product/product-name
To the desired URL structure of:
https://example.com/product-category-name/product-name
Conclusion
Changing the default product page URL structure to include the product-category-name can add more value to your URLs.
It can better show customers where they are on your store and to better inform them about your product range.
When adding product-category-name to your product URLs, you probably want to exclude the default “/product/” base slug in order to have shorter URLs.
Unfortunately, WooCommerce does not allow you to do this by itself.
Although with Permalinks Manager plugin, this can easily be achieved in a very small amount of time.
We hope this has helped you learn how to add the product category name to your product page URLs in WooCommerce.