Advertisement
Articles

WordPress Permalinks 101: What, How, When and Why to Use Them

by

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.
  • 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.
  • 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
  • %monthnum%
    The month that the post was published in
    Example output: 10
  • %day%
    The day that the post was published in
    Example output: 28
  • %minute%
    The exact minute the post was published in
    Example output: 45
  • %second%
    The second that the post was published in
    Example output: 38
  • %post_id%
    The post's ID, which could still be preferably used in conjunction with other text
    Example output: 123
  • %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
  • %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
  • %tag%
    A tag that the post's associated with's slug.
    Example output: awesome
  • %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.

/%category%/%postname%/

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:

/%year%/%monthnum%/%day%/%postname%/

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.

/%year%/%monthnum%/%day%/%minute%/%second%/%post_id%/

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.

/%author%/%postname%/

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!

Related Posts
  • Code
    WordPress
    Quick Tip: Post Types, Taxonomies and PermalinksPost types taxonomies urls
    Custom Post Types and taxonomies are two powerful features of WordPress. Unfortunately, they can have a tendency to cause problems if developers aren't familiar with how permalinks, URLs, and rewriting works within WordPress. In this quick tip, we aim to cover the topic very briefly to make sure you know all you need to know about WordPress URLs, custom post types, taxonomies, and how they all relate.Read More…
  • Code
    Theme Development
    Creating a WordPress Theme from Static HTML: Creating an Archive TemplateCreating wordpress theme from html 400
    If you've been working your way through this series, you now have a functioning theme with two page templates. The steps I've demonstrated to this point are: preparing your markup for WordPress converting your HTML to PHP and splitting your file into template files editing the stylesheet and uploading your theme to WordPress adding a loop to your index file adding meta tags, the wp_head hook and the site title and description to your header file adding a navigation menu adding widget areas to the header and sidebar adding widget areas, a colophon and the wp_footer hook to the footer file creating template files for static pages. Read More…
  • Code
    Plugins
    The Beginner’s Guide to WordPress SEO by Yoast: Final TweakingThe beginners guide to wordpress seo by yoast
    In my previous article, I discussed the social settings of Yoast's WordPress SEO plugin. In this tutorial, you will learn the final steps to configuring the WordPress SEO plugin with the ultimate goal of making it as rock-solid as possible for your blog.Read More…
  • Code
    Creative Coding
    Using WordPress For Web Application Development: Available Features, Part 6: URL Rewriting (or Routes)Application foundation 400
    One of the nicest things about modern web application development frameworks is that they provide a way to generate really clean routes—or URL schemes—that map to the conceptual model of how the application is structured.Read More…
  • Code
    Creative Coding
    The Rewrite API: Post Types & TaxonomiesPreview
    This is part two of a series looking at WordPress' Rewrite API. In part one we took a whistle stop tour of the basics of WordPress' Rewrite API. In this tutorial we will look at the rewrite settings available to us when registering a post type or taxonomy. While custom post types and taxonomies (unlike the default posts, categories and tags) don't benefit from any Settings -> Permalink interface, setting up rewrites for custom types is still fairly straightforward. We'll also be using the methods introduced in part one, so if you haven't already I recommend you read WordPress' Rewrite API Part One: The Basics.Read More…
  • Code
    Creative Coding
    The Rewrite API: The BasicsPreview
    This is part one of a two part series looking at WordPress' Rewrite API. In this tutorial we look at how rewrites work and the basic methods available to create custom rewrite rules.Read More…