WordPress Basix Article! Most major WordPress blogs nowadays are using permalinks (otherwise known as "pretty" URLs); WordPress gives us a few great tools for setting them up quickly and easily... but what do you really know about them? That's what we'll be exploring today. WordPress offers a bunch of options to "beautify" your permalinks from the standard question mark-prefixed number to a feigned path-style URL.

What is a Permalink?

Permalink is a portmanteau of permanent link because it's just that, a link to a specific post or page that will not change and will not suffer link death. By default, a WordPress permalink looks like this:

http://www.example.com/?p=14

This it the "permanent link" to a particular post on your site. It'll always be there so long as you don't delete it. Obviously, you want to swap out the 14 for your post ID and example.com with your domain.

A permalink is meant to be permanent because it will always point to a specific item of content, never changing. Whereas the homepage and different archive pages will change as new content is posted, the permanent link will always access the post or page that is defined in it's body. These are handled in different ways and some CMSes, like MediaWiki, have a timestamp in their permalink so when the wiki's page is edited, the permalink still links to the version at the time it was created.

However, http://www.example.com/?p=14 isn't what we'd call "human-readable" because, unless you know your entire database of posts and each one's associated ID, you can't interpret what it means other than it points to some post on that domain. So, WordPress has a solution in the form of "pretty" URLs that can easily be interpreted by a regular ol' human.

Permalinks in WordPress

WordPress offers the ability to choose a permalink style that suits your blog, containing different variables in a standard arrangement. As I previously mentioned, WordPress permalinks default to http://www.example.com/?p=14 but this is easily converted into a "pretty" arrangement. We'll go on to discuss how to do so, which type to use and why to use them.

Why use a Permalink?

As I mentioned in the last section, permalinks offer a permanent link back to a specific item of content. This means that, for as long as the blog is live, the link will always point to that content and can be referenced both externally and internally, without fear that the content will change. Permalinks can then be used when referencing another article in another post or page on any website since you can always rely on that to point to that piece of content.

Permalinks and SEO

Permalinks can also benefit your search engine optimization since those links that contain keywords can help them rank higher. Exactly how much that helps is debatable, but many SEO "experts" agree that those keywords can benefit your rankings.

In Google's search results, searchers are given four different pieces of information: the title, the description, the date and the permalink. This gives an end user an indication that the page contains the content you're looking for.

Creating a Permalink Format

In your WordPress dashboard, you can choose one of four standard permalink structures. The first one is the default structure we've already discussed, http://domain.tld/?p=123 , and should probably be changed if you want.

There's then three more structures based around numbers:

http://domain.tld/2011/10/28/post-title/ - The "day and name" structure shows a path based around a date, as if each post were organised into sub-folders based on date.

- The "day and name" structure shows a path based around a date, as if each post were organised into sub-folders based on date. http://domain.tld/2011/10/post-title/ - Very similar to the "day and name" structure, "month and name" has all the same structure tags minus the individual day. This is probably best for blogs that don't have a lot of posts per day.

- Very similar to the "day and name" structure, "month and name" has all the same structure tags minus the individual day. This is probably best for blogs that don't have a lot of posts per day. http://domain.tld/archives/123 - Out of these three formats, the numeric one is probably the worst, but it's still an option. The 123 is actually the post ID and there's probably only a few, unique blogs that this structure suits.

Custom Structures

The final option in the permalinks section of the WordPress dashboard is the custom structure, where you create a specific arrangement through structure tags. This leads to a great level of customization. Let's just go over what each of those structure tags translate to.

%year%

The year that the post was published in

Example output: 2011

The year that the post was published in %monthnum%

The month that the post was published in

Example output: 10

The month that the post was published in %day%

The day that the post was published in

Example output: 28

The day that the post was published in %minute%

The exact minute the post was published in

Example output: 45

The exact minute the post was published in %second%

The second that the post was published in

Example output: 38

The second that the post was published in %post_id%

The post's ID, which could still be preferably used in conjunction with other text

Example output: 123

The post's ID, which could still be preferably used in conjunction with other text %postname%

The post's slug, as defined in the post editor and can be customized there. If you don't set a custom one, WordPress will automatically clean your post title into a style like the example output (sans special characters).

Example output: this-is-an-example-post

The post's slug, as defined in the post editor and can be customized there. If you don't set a custom one, WordPress will automatically clean your post title into a style like the example output (sans special characters). %category%

The category that the post is entered in's slug. If it's a nested category, the permalink will show the full hierarchy. Only one category will be shown, however, the lowest numbered one.

Example output: (first level) tutorials

Example output: (third level) articles/tutorials/coding

The category that the post is entered in's slug. If it's a nested category, the permalink will show the full hierarchy. Only one category will be shown, however, the lowest numbered one. (first level) (third level) %tag%

A tag that the post's associated with's slug.

Example output: awesome

A tag that the post's associated with's slug. %author%

The post's author's slug.

Example output: connor

We enter the structure into the form field as if it were a URL with the different variables replaced with a respective tag. What's vital(!) is that you do not put your site's domain into the field.

So, let's imagine we wanted to recreate the permalink structure we have at WPTuts+. Here, a single post's URL looks like http://wp.tutsplus.com/tutorials/attaching-files-to-your-posts-using-wordpress-custom-meta-boxes-part-2/ . It contains a category and the post's name so we'd enter the following into the custom structure form field.

From there, it's fairly self-explanatory how you can create your own, blog-specific structure. You can create all types of different URLs.

Examples

Let's say you run a blog that focuses on news, and, therefore, dates are quite important, especially for SEO. You're going to want to create a structure that includes dates, something like this:

However, let's say you're running a liveblog or perhaps an installation using a Twitter-like theme like Prologue. In that case, you might want to include more date information like the minute.

What about a blog that publishes entries that are written by lots of different authors, but that aren't very time-specific? In that case, you probably want to include the author in the permalink as well as the post name.

Pretty simple, huh?

Categories and Tags

Using categories and tags in permalinks are considered "harmful" by WordPress when used first, and are recommended to be avoided. The Codex cites performance reasons for this, but there are other inconsistencies that should be taken into account if you opt to use these in your permalinks.

As we mentioned previously, the category shown in the permalink will be the lowest numbered one, if there's multiple categories assigned. In a hypothetical blog, if we assigned a post to both the "Web Design" category (that has the hypothetical ID of 36) and the "Print Design" category (with the hypothetical ID of 25), then the slug of the "Print Design" category will be shown in the permalink.

However, say you had another post on a very similar, related topic and placed it in the "Print Design" category (with the same ID of 25) and the "T-Shirt Design" category (that has the ID of 4), then the "T-Shirt Design" category's slug would be shown in the permalink. So, even though they might be very similar posts on very similar topics, the category in their permalink could be completely different which isn't very consistent, and definitely has it's flaws.

Nevertheless, there is still some cases where you might want to opt for this structure. A pet care blog covering blog cats and snakes might want to use it, since the two will probably rarely meet.

Enjoy your new permalinks!