Updating WordPress Permalinks

  • UserId: 1
  • Title: Updating WordPress Permalinks
  • Url: updating-wordpress-permalinks
  • Summary: Updating WordPress Permalinks
  • Search:
  • DateCreated:
  • DateModified:
  • Published: 1
  • Pageable: 1

After ironing out all of the bugs with my latest theme release, I decided to update the permalinks used throughout slickhouse.com

Thanks to WordPress' intuitive admin interface, this is a simple process:

admin

Most WordPress users opt for the Day and name Permalink structure, which would appear as 2008/05/04 for today. However, to a search-engine spider, this already looks like the links is 3 directories deep, before it even gets to the post title itself.

To counter this, I've amended the permalink structure to mirror the ISO 8601 standard for date (minus the time) - so today reads as 2008-05-04. To a search-engine spider, this would appear as just the one directory, within which the post title is situated.

There is a downside to amending permalinks to a WordPress blog that has been live for several months (even years) - all of the current links will effectively be broken. You could use a redirect script, that detects the user is trying to visit an older page - which would redirect them with a 301 (permanently moved) redirect to the amended url. However, this would still mean that your older links are present in your data.

To resolve this, you can amend all occurences of the older permalink to the new format. So, you'd look for 2008/05/04 and replace it with 2008-05-04.

sql

Using MySQL Administrator Query Browser, you can query the WordPress database, as above. The first step is to ensure you're querying the correct database (essential if you have multiple databases on the one server):

Use [database-name]

Where [database-name] is the name of your WordPress database. A standard install usually prefixes the database name with wp_. Execute the above and you'll see the correct database highlighted in the right-pane. Next, you want to begin searching for posts which contain the old permalinks within the content:

Select ID, post_title From wp_posts Where post_content Like 'example.com/2008/%' Order By ID Desc

If your WordPress database is fairly small (<500 posts), then you should find that the above query executes almost instantly - leaving you with a list of all posts that use the older permalink structure. You'll need to replace example.com with your domain name and run the query several times - once for each year your WordPress blog has been active, amending the year each time (2007, 2006 etc.).

Once you've got your list, you can start editing the posts to update the permalinks used. This could be achieved using SQL, but I would recommend doing it post-by-post to save any headaches if your update query goes horribly wrong!

Using the WordPress admin (Manage > Post) you can edit each post using the HTML view:

post

After editing a few, you'll soon quickly spot the a tags, ready to update them. In my case, it was simply a case of replacing the / with -, so 2008/05/04 became 2008-05-04.

There was a reason the SQL query brought back both the ID and post_title - as you'll soon find out when trawling through the admin. The admin orders (by default) the posts by ID, which means ordering the results of the Select query should make finding the offending posts a lot easier. To make things even simpler, you can amend the URL each time you have finished editing the one post and are moving onto the next:

url

As you'll see - the post.php references the posts by their IDs.

Once you've updated both your permalink structure and your content of each post, you'll be left with a fully working site. However, you may also want to notify the major search engines of your recent update. For this, I can highly recommend the XML Sitemap plugin for WordPress. After setting it up, it will generate an XML Sitemap of your WordPress blog and simultaneously notify each of the search engines of the updated sitemap.

Then, it's just a case of sitting back and awaiting the spiders as they begin to crawl your new, friendlier (in theory) permalink structure. If you haven't already setup Google's Webmaster Tools, then now is a good time - as it will help diagnose any issues with your new permalink structure.

Finally, if you don't have direct access to your WordPress database, then you could try using the built-in search facility, as seen in use on many themes. Simply search for your older permalink structure and it should disply all relevant posts.

Categories that this Post has been filed under

  • Articles - Longer posts that warrant an article status
  • Slickhouse - Anything to do with slickhouse.com in particular
  • Web - The Web, XHTML/CSS/ASP/.NET/SQL/PHP etc.

Tags that this Post has been tagged with

Comments

There are no Comments at this time.


Add a Comment