Using ‘Primary Category’ in URL

Question

I’m running into an issue where I want to set up categories in my URL (%category%/%postname%), but doing this will create multiple URLs for the same content if I select multiple categories.

So, for example, if I put a ‘Bugatti’ post in the ‘cars’ and ‘supercars’ categories, the ‘Bugatti’ post will be available at both ‘mysite.com/cars/bugatti’ as well as ‘mysite.com/supercars/bugatti’.

I want to restrict this to where the content will only be available for the primary category that I select. So if I select the category ‘supercars’ as my primary category, the post ‘bugatti’ will only be available at ‘mysite.com/supercars/bugatti’ and any secondary category URLs ( i.e. ‘mysite.com/cars/bugatti’, etc. ) would return a 404. Is there any way to do this using the ‘primary category’ from Yoast or otherwise?

I noticed that Wirecutter does this for their site. They’re running WordPress, using a %category%/%postname% permalink structure, but any of their secondary categories in the URL only return a 404.

Thanks for any help you can provide!

0
leighton_burley 4 months 0 Answers 15 views 0

Leave an answer