I need to customize my post URL (wordpress).
I use parent category and child category.
If i publish a post from child category, the URL is: domain.be/category/subcategory/post-title
but if i select the subcategory and the parent category, the url is: domain.be/category/post-title
i need, if i select the both, the url with cat and subcat.
In Wordpress BO > setting > permalink:
i don't want to use a plugin
First of all, When modifying the url permalink structure it is best practice to flush the rewrite rules using the Wordpress flush_rewrite_rules()
function.
Remove rewrite rules and then recreate rewrite rules.
You're actually on the right track, indeed you need to use /%category%/%postname%/
in your custom permalink structure.
For the purpose of this example, let's declare two categories, a parent and a child, Fruits
and Tomatoes
.
Fruits
└── Tomatoes
Wordpress uses the hierarchical alphabetical order to choose which category will be used in the url permalink structure. By default Wordpress can't display more than 1 category per level.
Behaviour | Description |
---|---|
Possible | eg: domain.com/parent/child/grand-child/my-first-post/ |
NOT Possible | eg: domain.com/parent-1/parent-2/my-first-post/ |
If we want our url to be domain.com/fruits/my-first-post/
we need AT LEAST to select the fruits
category.
If we want our url to be domain.com/fruits/tomatoes/my-first-post/
we need to select the tomatoes
category ONLY .
On your end, you simply need to unselect yhe top level categories associated with your child category and you should be good to go.
Thanks for contributing an answer
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.