How to choose which category appears in a WordPress post URL
When a permalink structure contains %category% and a post has several categories, WordPress uses the one with the lowest ID, which is simply the category that was created first. To choose it yourself, set a Primary Category in the editor with Hydrogen SEO, or filter post_link_category in code.
This only matters on sites whose structure looks like /%category%/%postname%/. With any other structure, categories never appear in post URLs and there is nothing to choose.
Step by step
1. Confirm that categories are in your URLs
Open Settings → Permalinks and read the structure. If %category% is not in it, stop: a post's categories affect breadcrumbs and archives but not its address. If it is, open a post that has two or more categories and look at its URL to see which one WordPress picked.
2. Understand the default choice
Core sorts a post's categories by term ID, lowest first, and uses the first. If that category has parents, they are included, so a post in "Brewing", a child of "Coffee", lives at /coffee/brewing/post-name/. A post with no category gets the site's default category in its URL. Nothing about the order you ticked the boxes, or which category is most relevant, is considered. That is why a general category made on day one, such as "News", tends to end up in URLs it does not describe.
3. Set a primary category in the editor
- Open the post and find Categories in the settings sidebar.
- With two or more categories ticked, a Primary Category dropdown appears under the list, noted Used in breadcrumbs, schema and permalinks. It starts at Not set.
- Pick the category that best describes the post.
- Update the post.
On a %category% structure, the post's address now uses that category and its parents. Breadcrumbs, schema and the %category% template variable use it too, so all four agree.
4. Redirect the old address when the post is already published
Changing the primary category of a live post changes its URL. WordPress does not redirect the old one here. Because the post is still in its former category, the old address keeps loading the post with a 200 status, and the canonical tag points to the new address. That is workable, but a redirect is cleaner. Add one in Hydrogen SEO → Redirections: the old path as From URL, Exact Match, the new path as To URL, 301 - Permanent Redirect.
5. Check the result
curl -sI https://example.com/news/espresso-ratio/ | grep -iE "^HTTP|^location"
curl -s https://example.com/coffee/brewing/espresso-ratio/ | grep -i 'rel="canonical"'
The first should be a 301 to the new address once your redirect exists. The second should show a canonical equal to the URL you requested. Purge the page cache first, since a cached copy of the old address still carries the old canonical.
6. Or choose in code, without the plugin
Core passes its choice through a filter, with the chosen category, the full list and the post:
add_filter( 'post_link_category', function ( $category, $categories, $post ) {
foreach ( $categories as $candidate ) {
if ( 'guides' === $candidate->slug ) {
return $candidate;
}
}
return $category;
}, 10, 3 );
This example prefers the "guides" category whenever a post has it. A rule like that suits sites with one clear hierarchy. A per-post choice needs a custom field and more code, which is the job the plugin's dropdown does.
7. Set it for existing posts gradually
There is no need to edit every post. Start with posts whose current URL category is plainly wrong, and with new posts from now on. A post with no primary category stored keeps exactly the URL it has today.
If you imported primary categories
Primary categories carried over by Tools → Import SEO Data are used in %category% permalinks from version 0.0.30, so some imported posts may have changed address after an update. If those addresses must stay, the hydrogen_seo_primary_term_in_permalinks filter switches the permalink effect off while breadcrumbs and schema keep using the primary category. Details are in primary category.
Is %category% in URLs worth having
It makes URLs longer and ties each post's address to a taxonomy decision you may want to change later. Every re-categorisation becomes a URL change with a redirect. If you are choosing a structure for a new site, /%postname%/ avoids the problem. On an existing site, changing structure is a bigger project than picking primary categories; see change permalinks without losing SEO.
Common questions
Which category does WordPress use in the permalink?
The category with the lowest ID among those assigned to the post, along with its parent categories. WordPress has no built-in way to choose a different one.
Does setting a primary category change my URL?
Only if your permalink structure contains %category%. Otherwise it changes breadcrumbs, schema and template variables, and the URL stays the same.
Does WooCommerce work the same way?
Product URLs that contain %product_cat% follow the same idea, and Hydrogen SEO uses the primary product category there.