Home > Software design >  How to display selected category in url?
How to display selected category in url?

Time:08-24

I have one product with 2 categories (e.g. apples/pineapples).

If I go to a product in the "Apples" category, "/product/apples/" appears in the URL. If I go to a product in the "Pineapples" category, "/product/apples/" appears in the URL.

How can I display the correct category in the url?

Product in the category "Apples" with url "/product/apples/". The same product in the "Pineapples" category with the url "/product/pineapples/".

CodePudding user response:

Actually (I think that) you can't do that! Because every product has its only one page with only one link (or Slug) !

Like, If a product can have "n" links (1 link for each category is related to), there will be "n" extra pages for this product (each one with its proper link).

Hope you understand what I meant above.

If you have any other question, I'll be glad to help.

CodePudding user response:

As Nova mentioned, by default WordPress associates one category for a post (ie. product, blog, etc.) as the primary category, and utilised in the URL.

A possible implementation to resolve your challenge would be to simply create two products (one per category). However, this could come unstuck if you're needing to utilise stock limits.

  • Related