Skip to content

Everything for WordPress, web development — and beyond

🛠 How to add category and subcategory to WordPress permalinks

🛠 How to add category and subcategory to WordPress permalinks

Default WordPress URLs look like site.com/?p=123, a string of numbers that tells neither search engines nor readers anything. You can switch to site.com/sample-post/ through the permalinks settings, which is already a step forward. But when a blog has 50, 100, 500 articles, having just the post name in the URL isn't enough.

Categories in permalinks solve three problems at once: they show the site structure, add keywords to the address, and help readers understand where they are. And if you have breadcrumbs enabled, the combination of categories in URLs and navigation works even better.

Let's look at how to add a category and subcategory to WordPress permalinks, and how to remove them if you change your mind. Everything through standard settings, no plugins needed for the basic scenario.

💡 Quick overview:

  • Go to Settings → Permalinks and select "Custom Structure"
  • Insert /%category%/%postname%/ and save changes, categories will appear in all post URLs
  • Subcategories are picked up automatically: if a post has a parent and child category, both will appear in the URL
  • To remove the category from URLs, add a dot before the structure, edit.htaccess, or install the Remove Category URL plugin

Why categories in URLs

Categories aren't just a way to group posts in the admin panel. If you run a blog about WordPress, you might have sections like "Plugins", "Themes", "Security", "SEO". When a reader sees the URL site.com/seo/kak-nastroit-permalinky/, they instantly understand: this is an article about SEO, not about design.

From a search engine perspective, an extra keyword in the address never hurts. Google uses URLs as one of the ranking factors, and a meaningful structure like site.com/category/post-name/ provides more context than a flat site.com/post-name/.

Another plus, breadcrumbs. If you have breadcrumbs set up (via Yoast SEO, Rank Math, or your theme), the category from the URL syncs with the navigation trail: readers always see the path to the current article and can go back one level with a single click.

The setup takes a minute through the standard WordPress admin panel. No plugins required.

Go to the WordPress Dashboard, navigate to Settings → Permalinks. You'll see a list of preset formats: "Plain", "Day and name", "Month and name", "Numeric", "Post name", and "Custom Structure".

Select Custom Structure and in the input field enter:

1/%category%/%postname%/

Click Save Changes.

WordPress custom permalink structure field

Done. Now all post URLs on your site will include the category the post is assigned to. For example, an article from the "Security" category will get the address site.com/bezopasnost/nazvanie-posta/.

One important caveat: if you just created the site and haven't added your categories yet, WordPress will use the default category, usually "Uncategorized" (or uncategorized). As a result, the URL will become site.com/bez-rubriki/vash-post/, which looks messy. So before changing the permalink structure, create proper categories and distribute posts among them. For more on changing the default category, see our guide.

How to display subcategories in URLs

WordPress supports category hierarchy: you can have "Plugins" (parent) and within it "Caching Plugins" (child). If a post is assigned to a child category, WordPress will automatically include both in the URL.

The structure is the same, /%category%/%postname%/. When a post has one parent and one child category, the address will look like:

1site.com/plaginy/plaginy-keshirovaniya/nazvanie-posta/

But there's a nuance here. If a post is assigned multiple categories (say, "SEO" and "Plugins"), WordPress needs to choose one, the primary one, to form the URL. By default, the system picks the category that comes first alphabetically. This doesn't always match your intent: you wanted to show "SEO", but WordPress chose "Plugins" because the letter "P" comes before "S".

The solution, set the primary category manually. To do this, when editing a post in the "Categories" sidebar, mark the needed one as primary (in the Gutenberg block editor, the "Set as primary" button in the category menu). After that, it will be used in the URL.

There are situations when categories in URLs get in the way. For example, you're migrating the site to a new structure, changing the taxonomy, or simply decided that flat URLs work better for your project. Here are three ways to remove the category prefix.

The simplest method, add a dot before the structure in the "Custom Structure" field.

Go to Settings → Permalinks, select "Custom Structure" and enter:

1./%category%/%postname%/
Adding a dot before the structure to hide the category

The dot before the slash forces WordPress to ignore /category/ when forming URLs. Save changes and check any post's address, the category is gone.

This trick works in most WordPress versions, but it's not a documented feature. There's no guarantee it will remain in future updates. If you need a stable solution for years to come, see method 3 (plugins).

Method 2: Editing.htaccess

If you're working on an Apache server, you can add a redirect rule to the .htaccess file. It's located in the WordPress root directory.

Add the following code before the standard # BEGIN WordPress block:

1RewriteRule ^category/(.+)$ http://www.yourwebsite.com/$1 [R=301,L]
RewriteRule code in WordPress .htaccess file

Don't forget to replace yourwebsite.com with your actual domain. The rule performs a 301 redirect: all URLs starting with /category/ are redirected to the same addresses without the category prefix.

Important: before editing .htaccess, make a backup of the file. A syntax error can bring down the entire site (error 500), and without a backup restoring access will be difficult. If you're unsure about your actions, better use the plugin from the third method.

Method 3: Using plugins

The most reliable and safe way.

Remove Category URL, a free plugin that does exactly what the name says. Activate it, and the /category/ prefix disappears from all URLs. No settings needed, works automatically. Compatible with WordPress Multisite, WPML, and popular sitemap plugins. After activation, the sitemap updates with the new URLs.

The plugin is regularly updated and tested for compatibility with current WordPress versions. If you updated Yoast SEO and discovered that the category removal feature disappeared (they removed it in later versions), Remove Category URL will solve the problem in a minute.

Watch a short video guide on configuring categories and subcategories in WordPress URLs. All the steps from the article, demonstrated visually, in 5 minutes.

⁉️🤔 Frequently asked questions

What happens to old URLs after changing the permalink structure?

WordPress automatically creates a 301 redirect from old addresses to new ones when you change the structure through standard permalink settings. Check a couple of old URLs after making changes, if the redirect didn't work, install the Redirection plugin and add a rule manually. Old bookmarks and links from other sites should not break.

Can I add a category to URLs only for some posts?

Using standard WordPress features, no. The permalink structure is set globally for the entire site. If you need selective control, you'll need custom code or a plugin like Permalink Manager Lite, which allows you to override URLs at the individual post level. But for most blogs, a global structure with categories is a plus, not a minus.

What if a post has multiple categories and the wrong one ends up in the URL?

WordPress selects the category for the URL alphabetically if a primary one isn't explicitly set. When editing the post, go to the "Categories" block, find the one you need, click the three dots next to it and select "Set as primary". After saving the post, it will appear in the permalink.

Will changing permalinks affect SEO?

Yes, in both directions. Switching from ?p=123 to /%category%/%postname%/ provides gains from keywords in URLs. But frequent structure changes back and forth are harmful: search engines can't keep up with reindexing addresses, 404 errors accumulate. Choose a scheme once and stick with it. If you still had to change it, make sure old URLs return a 301 redirect.

Is the Remove Category URL plugin safe for a large site?

Yes, the plugin works at the WordPress Rewrite API level and doesn't directly touch server files, unlike manual.htaccess editing where a syntax error breaks the site. On sites with 500+ posts and an active sitemap, the plugin works correctly: new URLs are picked up by the sitemap automatically.

What to use: categories in URLs or flat structure

Short answer: for a content blog with topical sections, definitely categories in URLs. This provides SEO gains from additional keywords in the address, improves navigation through breadcrumbs, and helps readers orient themselves. For a business card site with five pages or a landing page, the difference is negligible, do whatever's easier.

If you're just launching a site, set up /%category%/%postname%/ from day one and forget about it. Create the categories that go into URLs in advance and meaningfully (not "Misc 1", "Misc 2"). Set the primary category for each post manually.

If the site is already running and you're changing the structure, act carefully: check redirects from old URLs, update the sitemap in Google Search Console, and monitor the Coverage panel for 404 errors during the first two weeks. The Redirection plugin is your best friend during this period.

And if categories in URLs get in the way for some reason, Remove Category URL removes them in a minute, without code editing and the risk of breaking the site.