Primary Category in WordPress: What It Changes
How WordPress picks the category in a %category% permalink, what a primary category changes in URLs, breadcrumbs and schema, and when to leave it alone.
In this article 8 sections
A primary category is the one category, out of several a post belongs to, that represents the post wherever only one can be shown: in the URL, in the breadcrumb trail, in structured data. WordPress itself has no such setting. It lets a post sit in any number of categories and then picks one by a fixed rule when it has to. This guide explains that rule, what a primary category setting changes, when it is worth using, and what to check before changing it on a published post.
What WordPress does without one
Three places need a single category.
The permalink. If your permalink structure under Settings → Permalinks contains %category%, for example /%category%/%postname%/, WordPress has to put one category in each post's address. It sorts the post's categories by ID and uses the lowest, the one created first, along with its parent categories. A post in "News" (ID 4) and "Recipes" (ID 9) gets /news/sourdough-starter/, whichever fits better. Create a new category later and it will never win, because its ID is higher.
Breadcrumbs. WordPress has no breadcrumbs of its own. Themes and plugins that add them each choose a category in their own way: the first alphabetically, the lowest ID, or the deepest in the hierarchy. The breadcrumb on the page and the category in the URL can therefore disagree.
Structured data. Article markup has an articleSection property, and breadcrumb markup lists the trail. Whatever generates them makes its own choice again.
None of this matters for a post in a single category. It starts to matter when posts are filed in two or three and you care which one is shown.
What a primary category changes
A primary category is a per-post setting, added by a plugin or by a few lines of code, that replaces those separate rules with one choice. Typically it controls:
| Place | Effect |
|---|---|
The post's URL, with %category% in the permalink structure | The primary category's slug, and its parents, appear in the address |
| Breadcrumbs | The trail runs through the primary category |
| BreadcrumbList structured data | Matches the visible trail |
articleSection in Article structured data | Names the primary category |
| Category shown in titles or post meta, where a template prints one | The primary category |
What it does not change:
- Which archives list the post. The post still appears in every category it is assigned to.
- Rankings, directly. There is no "primary category" signal for search engines. The effect is that your URL, the breadcrumb search engines may show in place of the URL, and your markup all agree on the section, and that the section is the one you would choose.
- Posts in one category. There is nothing to choose.
Does your site need it?
Check two things.
- Your permalink structure. If it does not contain
%category%, the URL question does not arise, and a primary category only affects breadcrumbs and markup. - How many posts are in more than one category. If the answer is "hardly any", the setting will sit unused.
It earns its place on sites where multiple categories are normal: a recipe site where a dish is both "Dinner" and "Vegetarian", a shop where a product is in "Sale" and "Kettles", a news site filing by topic and by region. On those sites the lowest-ID rule produces results such as every discounted product showing a breadcrumb through "Sale", which tells a visitor nothing about what the product is.
A cheaper fix is sometimes better. If posts are in several categories out of habit, use one category per post and tags for everything that cuts across. A primary category is for cases where the multiple categories are real.
Before you change it on a published post
With %category% in your permalinks, changing a post's primary category changes its address. It is a URL change with one difference from most: the old address does not redirect.
- The old address keeps working. WordPress redirects a category permalink only when the post is not in the category named in the URL. The post is still in "News", so
/news/sourdough-starter/goes on loading it with a 200 response. Its canonical tag points to/recipes/sourdough-starter/, which is how search engines learn which address counts. Open the old address and check the canonical in the page source. - Internal links keep the old address. They still work, but they lead to a second copy of the post. Update the important ones.
- Search engines take time. A canonical tag is a strong hint, not an instruction, and the old address can stay in results until it has been crawled again.
- Shares and backlinks point at the old address and rely on that canonical tag. If you need a redirect, add a 301 for the old address yourself.
If you also take the post out of the old category, WordPress does redirect the old address to the new one.
So the rule of thumb: set the primary category before publishing. On an existing post, change it when the current category is wrong enough to be worth a URL change, and leave it when it is merely not the one you would pick today. Without %category% in the structure, none of this applies and you can change it freely.
If you are planning to change the structure itself, read about changing permalinks without losing SEO first.
Doing it in code
WordPress exposes the permalink decision through the post_link_category filter. This is enough to drive the URL from a custom field holding a category ID:
add_filter( 'post_link_category', function ( $category, $categories, $post ) {
$primary_id = (int) get_post_meta( $post->ID, 'primary_category_id', true );
foreach ( $categories as $candidate ) {
if ( (int) $candidate->term_id === $primary_id ) {
return $candidate;
}
}
return $category;
}, 10, 3 );
The loop matters: it only accepts a category the post is still assigned to, so a stale ID falls back to WordPress's own choice. Breadcrumbs and markup need the same lookup wherever your theme builds them, which is the part that makes a ready-made setting attractive.
Doing it with a plugin
Hydrogen SEO 0.0.30 adds a Primary Category dropdown to the editor's Categories panel. It appears once a post has two or more categories ticked, in the block editor and the Classic editor, and for WooCommerce product categories. The choice drives %category% permalinks, the plugin's breadcrumbs and BreadcrumbList markup, articleSection, and the %category% variable in title templates. The picker never chooses for you, so posts where nothing is chosen keep WordPress's behaviour. Posts that already carry a primary category from an earlier import start using it in their permalinks; the hydrogen_seo_primary_term_in_permalinks filter switches that off. It is free; the reference is primary category.
Whatever you use, check three things after setting it on a test post: the address in the browser, the breadcrumb on the page, and the BreadcrumbList in the page source. All three should name the same category.
WooCommerce products
Products follow the same logic with product categories. If your product permalinks include %product_cat%, WooCommerce chooses a category for the address, and its breadcrumb chooses one too. A primary product category makes both follow your choice. The caution about published URLs applies with more force, since product addresses collect adverts, feeds and marketplace listings as well as links. See optimizing WooCommerce category pages for the archive side.
Common questions
Is the primary category the same as the default category? No. The default category, under Settings → Writing, is the one WordPress assigns to a post saved with none ticked. The primary category is a per-post choice among the categories the post has.
Can a subcategory be primary? Yes. Its parents are then included in the URL and the breadcrumb, as in /recipes/bread/sourdough-starter/.
Should the primary category be the most specific one? Usually. It gives the clearest breadcrumb and the most descriptive URL. Choose the broader one when the specific category is thin or likely to be renamed.
What happens if I remove the primary category from the post? A well-behaved setting falls back to the default rule. Check after re-categorising, because on %category% permalinks that means the address changes again.
Related glossary entries: permalink and breadcrumbs.