writer, web developer, designer

From the Blog

May
12

WordPress Slugs

Posted by Shell on May 12th, 2011 at 2:26 pm

I love WordPress, lets be frank, if you are developing your own themes there are some wonderful gotchas just waiting to trip us up. Today’s little adventure revolves around how WordPress handles “slugs”, those little browser-safe representations of posts, categories and tags you see in your address bar.

Example slug:

http://www.shellbryson.com/category/edinburgh/

The issue I found today is that slugs are actually shared across multiple types of content – so for example, if you have tagged a post as Edinburgh (with a slug of ‘edinburgh’), if you then try to create a category also called Edinburgh, WordPress will create a slug something along the lines of “edinburgh-1″. No big deal, right? But it looks nasty in the address bar:

Example bad slug:

http://www.shellbryson.com/category/edinburgh-2/

Solution

If you try rename the edinburgh-2 to edinburgh slug in the WordPress admin, it won’t let you (however it won’t warn you that it hasn’t saved your change).

Given categories are more frequently exposed in the addressbar than tags, it makes sense to instead use the Admin to change the slug for the tag instead, and indeed this does work. Happy days.

Leave a Reply

  1.  

    |