Spending entirely too much time on the Internet

Choosing a URL Naming Convention for WordPress (aka Permalink Structure)

By

There are a handful of good ways to structure the URL naming convention for WordPress. The most common are:

  • /%category%/%postname%
  • /%postname%
  • /category/%postname%-%post_id%
  • /%postname%-%post_id%

All of those options work well, but I actually prefer to do mine as /%post_id%/%postname%/. At first glance, that choice may seem less than ideal. For example, why would I want to exclude my category name, and what purpose does it serve having the post ID in the URL?

Category Name

While having the category name in the URL is not a bad idea, I don’t think it’s necessary. Google can easily understand that a blog entry is related to a particular category by simply mapping the linking structure. It will also be reinforced by the page title and internal link structure on the entry.

It’s also not desirable, because an entry can have multiple categories, and it can take up a lot of space in the SERPs. I prefer to show the the title of the blog entry, instead of the category name. In fact, showing the category name before a long title may cut off the title in the SERPs.

Not including the category in the URL of the entry also allows you to rename the category at a later time without having too much of a negative impact. I would much prefer to rename a category list page (which most people will not link to) than to change the URL of a post. If I’m really concerned about losing a list page, then I can go out of my way and set up a simple redirect in my .htaccess file.

Post ID

Most people consider displaying the post ID mainly because they’re concerned they might write a blog entry one day that uses the same title, causing an issue with resolving to the correct destination content. While that certainly factors into my decision to use a post ID before the post name, it’s not my main reason. I like using the post ID, because it handles changes to the blog entry gracefully.

If you change the page title and the permalink of a blog entry – like /id/original-blog-title to /id/new-blog-title – the old link will still resolve (correctly redirect to the new permalink.) That’s because WordPress reverts to the post ID when something goes wrong. In fact, you can go to just the post id (like the one for this entry: http://henshaw.me/423/) and it will bring up the correct blog entry. It won’t bring up the full permalink, but there’s no need to worry about duplicate content, that is, as long as you’re specifying the canonical URL in the HEAD area.