How to include the category in the URL?

So i have a post type called knowledge base http://www.domain.com/knowledge_base/
and i am going to have posts under categories. So it would look like http://www.domain.com/knowledge_base/category1/hello
and
http://www.domain.com/knowledge_base/category1/helloagain

the thing is that if i click go to my first post, lets say “random_post” that belongs to the category “Category 1”

instead of seeing
http://www.domain.com/knowledge_base/category1/random_post
It says
http://www.domain.com/knowledge_base/random_post

Where can you change it so it includes the category on the URL?

Also how would you do the blade file for the categories? would it be category-slug.blade.php?

If you want to make custom urls, you’re going to need to dig into WordPress’s Rewrites API. This post (though old) has a pretty decent walkthrough for how that works: https://www.pmg.com/blog/a-mostly-complete-guide-to-the-wordpress-rewrite-api/ The short version is that you have to tell WordPress how to parse particular URL segments into query terms it can understand.

As for the blade file, look at the hierarchy and determine what filename matches the endpoint you want: https://developer.wordpress.org/themes/basics/template-hierarchy/

This topic was automatically closed after 42 days. New replies are no longer allowed.