Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have my permalink format set to /%category%/%postname%/ and I have two posts with the same permalink slug, but in different categories.

Ideally, the two permalinks should look like this:

http://example.com/category-1/post-title/
http://example.com/category-2/post-title/

But when I publish the second post, then its slug is changed to post-title-2, which makes the resulting URL http://example.com/category-2/post-title-2/.

How can I use the same slug for multiple posts that are in different categories? This WordPress Support topic suggests using an outdated plugin that doesn't work anymore.

share|improve this question
2  
What should happen with a post that is in both categories? –  toscho Apr 14 '13 at 7:53
    
@toscho The whole permalink should be checked as a duplicate instead of just the slug. –  bungeshea Apr 14 '13 at 8:33
    
You would have to override the whole redirect_canonical mess. This is very error prone. –  toscho Apr 14 '13 at 8:35
    
@toscho What if this special functionality was disabled if the post is in two categories, instead? –  bungeshea Apr 14 '13 at 8:40
add comment

1 Answer

up vote 0 down vote accepted

The best method is to find another way to structure your URLs that doesn't break unique slugs. Even though you may not have any plans to do so now, you may need to change the URL structure of the site down the road in such a way that having duplicate slugs would break the site. Furthermore, there may be unforeseen second- and third-order consequences to doing this, such as plugins that won't work or, worse, will cause fatal errors on the site because of slug collisions. Slugs are kept unique for a reason, and removing this check could wreak havoc going forward.

If your reason for wanting non-unique slugs is to make clean hierarchical URLs for easy sharing in non-linkable areas (print, images, etc.) you may want to consider using something like Quick Post/Page Redirect to allow simple URLs to forward to their full, more complex actual locations using a 301 redirect. It's not the most elegant or scalable solution, but it's not going to break compatibility the way non-unique slugs will.

If you just want attractive URLs for the sake of cleanliness in the browser, I'd recommend coming up with an alternative URL structure that can take advantage of unique slugs, such as incorporating the category name into the slug.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.