The Ultimate Guide to WordPress Permalinks
Pretty permalinks are the default setting for URLs on WordPress sites, but what exactly makes them pretty? And if you’re new to WordPress, you might be wondering what is a permalink?
Permalinks, or permanent links, are URLs to individual pages and posts, as well as category and tag archives, on your website. They never change and are a permanent web address used to link to your content.
Well-organized permalinks are important in both attracting users to your site, making it easy for visitors and search engines to navigate and refer to your content.
In this post, we’ll explore how permalinks work in WordPress, how you can manage the settings in the backend of your site to optimize your SEO, and some advanced settings to ensure permalinks work correctly on your server.
- Permalinks in WordPress
- Changing Your Permalink Structure
- Creating Custom Permalinks
- SEO-Friendly Permalinks
- Choosing the Right Permalink Structure for Your Site
- Enabling Pretty Permalinks
- Changing Permalinks on a Live Site
Permalinks in WordPress
There are three basic types of permalink available:
This is the default option in WordPress and takes the form of a URL followed by a query string identifying the relevant post ID, for example, http://www.example.com/?p=138. This format isn’t readable to humans (i.e. contains numbers rather than words), hence the name “ugly.”
“Almost Pretty” Permalinks
Also referred to as PATHINFO permalinks, these are an improvement on ugly permalinks. They include
index.php after the domain name followed by specific identifiers relating to a post, for example, http://www.example.com/index.php/yyyy/mm/dd/post-name/
These are the links you’ll be most familiar with from the majority of modern sites, WordPress or otherwise. In this case, the domain name is followed by a clean string of identifiers targeting the individual post, for example, http://www.example.com/2016/01/09/my-new-post
Changing Your Permalink Structure
Go to Settings > Permalinks in the backend of your site to access the permalinks settings.You can choose from one of the more common permalink structures or enter your own in the
You can choose from one of the more common permalink structures or enter your own in the Custom Structure field.
There are six options to select from:
- Plain: This is the “ugly” permalink setting
- Day and name: This uses a year/month/date format followed by your post’s name. The name here refers to the slug of your post
- Month and name: This is the same as option two but without the day information
- Numeric: This options just uses the ID of the post from the row in the
wp_poststable of your database
- Post name: This one uses the name of your post
- Custom Structure: This last field allows you to define your own structure using the full set of structure tags available in WordPress
The default setting is plain, or “ugly” permalinks, which is automatically set when you install WordPress.
Creating Custom Permalinks
WordPress provides 10 structure tags for defining your own custom permalink structure. The first seven are the ones you’ll come across most often:
%postname%: Your post’s slug
%post_id%: A post’s unique ID
%category%: The main category of a post
%year%: The year of the post
%monthnum%: The month a post was published
%day%: The numeric day a post was published
%author%:Potentially useful in multi-author, magazine type environments
If you want to get hyper-specific about timings with your permalinks, you can also use the
%second% options, though it’s hard to think of typical scenarios where these would actually be useful.
Bear in mind that when you’re putting together your custom structure, you’ll have to include at least one of
%post_id% in order for WordPress to be able to target a specific post – these are the only tags that give guaranteed unique identifiers to work with.
With all that in mind, if you wanted to create a custom permalink structure comprising solely if post IDs and post names, you would enter the following:
It’s worth mentioning at this point that you’ve also got the option of setting custom category and tag bases for your site on the same screen under the Optional settings section.
Permalinks and link structure are important from the point of view of search engines. While there’s been a lot of hot SEO air expounded on this topic over the years, Google’s guidelines on URL structure remain admirably straightforward – keep them as simple as possible and make them intelligible to humans.
In Google’s search results, users are given four different pieces of information: the title, the description, the date, and the permalink. These details give users a quick indication of whether a page contains the content they are seeking. For example, if you have a post about mountain goats and you leave the default permalink settings enabled, the URL might be http://www.example.com/?p=135 whereas if you enable the post name setting the URL might be http://www.example.com/mountain-goats/, which is far easier for humans to read and understand. As such, ugly permalinks aren’t so user-friendly and generally aren’t recommended for best practice SEO.
A recent Moz.com article on the subject fleshed things out slightly further on this front but, again, the basics aren’t hard to grasp:
- Keep URLs short – ideally under 100 characters
- Use keywords in URLs within reason, but don’t attempt to keyword stuff
- Remove dynamic properties where possible
- Use hyphens as separators and omit stop words such as and, or, but, of, the
Choosing the Right Permalink Structure for Your Site
We’ve covered the basic options for taking control over your permalinks so far, but we still haven’t grasped the nettle of what the ideal permalink structure for a WordPress site is. The short answer: it depends. Not every site will benefit from the same structure, but there are some general points to bear in mind.
Our best pro WP tools in one bundle
The first is that you almost certainly want to be including your post name in your permalinks. Its combination of utility for both site users and search engines makes it something of a must-have, and it’s often all you need. Browse around the WPMU DEV blog archives, for example, and you’ll see that’s the structure we use.
If you’re running a site that’s primarily focused on news, there’s a case to be made for including date information in your permalinks, but otherwise it’s hard to justify. If you do want to include date information as a courtesy to the reader, it makes a lot more sense to simply include it in your post’s meta information, where it’s more easily scanned.
Including category information in your URLs can make sense in the context of sites with discrete and well-defined sections of interest. Bear in mind that if you are using multiple categories for a post, only one will be displayed in the permalink and priority is given alphabetically. If you need more fine-grained control over this, consider using the WP Category Permalink plugin.
As long as you are including post name information in your URL, the precise solution you go for is unlikely to have an enormous impact one way or the other. Prior to WordPress 3.3, there was an issue where using post names in permalinks led to a performance hit, but those days are happily gone.
As Matt Cutts, former head of the web spam team at Google, points out, once you’ve got the basic info into the permalink, the exact structure you go for is largely a matter of personal choice.
Enabling Pretty Permalinks
Depending on the peculiarities of your particular hosting setup, you may need to ensure certain settings on the server are in place for permalinks to function correctly. Put simply, your web server needs some way of being able to translate permalinks into something it can actually target. How this is done will depend on which type of web server you’re using. With many hosting providers, these details will already have been taken care of, but you might find yourself needing to pop the hood from time to time.
We’ll introduce the most common setup below, but if you find yourself running into difficulty generally, the Fixing Permalink Problems of the Codex is an excellent place to start troubleshooting.
Using Permalinks on Apache
For the majority of WordPress sites, the web server being used will be Apache. If this is the case, you’ll need to be sure that a few technical pre-requisites are present and correct.
Firstly, Apache’s mod_rewrite module must be installed and activated. In WordPress’ home directory, you’ll also need the FollowSymLinks option enabled and FileInfo directives permitted – you can find a useful breakdown of how to do this in Apache configuration files over at Super User.
You’ll then also need a
.htaccess file in place that WordPress can use. If this doesn’t exist, WordPress will try to create it when you activate pretty permalinks and will also need write access to the file.
.htaccess files can be a messy business at the best of times, so we’d advise against diving straight in here unless you have some prior experience. You can find detailed info on using
.htaccess files in this context at the Using Permalinks WordPress Codex page.
Assuming those items are in place, you should then be able to manage your actual preferences from the WordPress backend.
Using Permalinks on Other Web Servers
Apache is, of course, far from the only server in widespread use. Popular alternatives include Nginx and Lighttpd. You’ll find instructions for using permalinks with both in the WordPress Codex, along with tips on getting up and running with Windows servers and local installs on Mac and PCs.
Changing Permalinks on a Live Site
Ideally, you should decide on your preferred permalink structure prior to site launch and then stick with it over time.
You may, however, end up having to make changes on an existing site at some point. Bear in mind that this is a large step to take sitewide, and you are potentially playing with fire when it comes to existing external links and SEO rankings.
Making the changes in the WordPress backend should be straightforward enough, but you will need to 301 redirect all of your previous links to ensure you don’t antagonize both users and search engines. Begin by making sure you have a complete list of both the previous URLs and what they will be redirecting to.
Ideally, you’ll then want to use a plugin such as Redirection or SEO Redirection Plugin to handle the heavy lifting of making sure old links still find the right target. Be sure to check out our overview of 301 redirects in WordPress for a complete breakdown of the subject and guide to relevant plugins you can use.
Getting your permalink structure defined is one of the first decisions you will likely make on any new WordPress site.
From an SEO and performance perspective, it’s best not to use the default “ugly” permalink settings and instead opt for a “pretty” permalink structure that is humanly readable. It’s also important to keep Google’s URL guides in mind when setting slugs for your site and when editing URLs for posts and pages.
Lastly, make sure you if you do decide to change your existing permalink structure on a live site, you do it with a large degree of caution and ensure you put in place tools to handle redirections.Tags: