Using WP Post Slugs for True Permalinks

Alex and I had a IMversation the other day about an issue I’d run across: in WP v1.0.x, the options for cruft-free URL‘s include:

  • %year% — The year of the post, 4 digits, for example 2004
  • %monthnum% — Month of the year, for example 05
  • %day% — Day of the month, for example 28
  • %postname% — A sanitized version of the title of the post. So “This Is A Great Post!” becomes “this-is-a-great-post” in the URI
  • %post_id% — The unique ID # of the post, for example 423

An issue arises when someone wishes to change the title of the entry. An example is my Case for a Comment Registration System, which I have since realized is really better named a User Registration System. If I change the title, all existing permalinks—including TrackBacks I’ve made previously, which I cannot edit—die a horrible, nasty death.

As a permalink should be, well, permanent, this is bad.

WP 1.2, however, introduced the concept of the Post Slug. As the link notes, %postname% is now set to look for the Post Slug, rather than auto-sanitizing the title. [I haven’t looked into the MySQL to see if this was actually being done in 1.0.x, but I’m guessing not.] If your permalinks are set to use the slug rather than the title, you’ll be able to change your title without killing inbound permalinks.

Beautiful, that.

Even more amusing, one could set the post slug to something completely unrelated [if one was of the mind to do so]. For instance, I could make this entry’s post slug “my left foot”, which would be amusing to me but not good for the reader trying to get context for the entry from its URL. [In my book, the context value of the URL’s naming scheme is important enough that you don’t want obfuscatory post slugs, but YMMV.

This functionality solves that problem, Alex.


Comments are closed.