Use category base slug in posts’ permalink

The Goal

I would like to format my permalinks as follows:

  • for posts: somePrefix/%category%/%postname%
  • for categories: somePrefix/%category%

Where somePrefix is the same in both cases.

I know that there is no big upside to this – it just seems “clean” to me 🙂 . And it comes in handy if you want to manually edit the URL.

What I Tried

No Category Base

One approach is to define the posts’ permalinks as /%category%/%postname%/ and use a plugin to get rid of the category base. Unfortunately those plugins seem to be buggy and are discouraged to use (e.g. by Yoast SEO Plugin).

Same Category Base

No problem, I thought, let’s just use the category base in the permalinks as so: category_base/%category%/%postname%. This produces:

  • for posts: example.org/category_base/%category%/%postname%
  • for categories: example.org/category_base/%category%

This works for the categories but now links to posts produce 404s.

Now What?

So is there a way to achieve this? A setting, a plugin or perhaps even hacking WordPress a little to properly process the links which created by Same Category Base?

2 s
2

I may be missing some vital detail in the question but here’s what I did to make this work.

Settings -> Permalinks

Set the permalinks to…

/somePrefix/%category%/%postname%/

This will give you the following permalinks…

Blog Page     - domain.com/somePrefix
Category Page - domain.com/somePrefix/currCategory/
Single Page   - domain.com/somePrefix/currCategory/singlePost/

If you install some kind of plugin like Yoast you’ll be able to pick a “Primary” category for your permalink which is nice.

Leave a Comment