#20399 closed defect (bug) (invalid)
WordPress removing multiple dashes/hyphens breaks my permalinks
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | General | Version: | 3.3.1 |
| Severity: | normal | Keywords: | |
| Cc: |
Description (last modified by johnbillion)
Recently been trying to upgrade to WordPress 3.3.1 but a lot of our writers use characters like ~ and " in their titles, which am fine with as WordPress has always changed these to dashes. So our URLs have multiple dashes/hyphens.
I have tracked this down to line 892 of /wp-includes/formatting.php which is:
$title = preg_replace('|-+|', '-', $title);
and so it replaces more than 1 consecutive occurance of - with a single -. And this is as the point the code checks the database. Thus a URL e.g. "colin---wiseman---2012" gets changed to "colin-wiseman-2012" which is not a name of a post in the database.
We cannot go back and change all our URLs as there are 1000s of pages and linked to from all around the internet.
The only solution I have found is to comment out this line, but I'd rather there be an option in WordPress that I can flag in the wp-config e.g. define("SANATIZE_DASHES", false); so that the next time I upgrade wordpress there isn't this issue.
I feel that until then, this is a serious bug that could be affecting more blogs than just mine.
Change History (7)
comment:1
johnbillion
— 15 months ago
- Description modified (diff)
comment:2
in reply to:
↑ description
SergeyBiryukov
— 15 months ago
comment:3
colinwiseman
— 15 months ago
- Resolution set to invalid
- Status changed from new to closed
It appears the version of WordPress I am working with was modified over 2 years ago (maybe by me, but there has been a couple of developers and no code respository). This has caused our issues, but am confused as we have upgraded a couple of times!
Please ignore this now while I go try and fix this! 2272 posts have multiple dashes in them :S
comment:5
nacin
— 15 months ago
Note that WordPress stores old post slugs in postmeta and then automatically does a 301 redirect from an old slug to a new slug.
So it should be relatively easy to handle.
comment:6
colinwiseman
— 15 months ago
How would I have it set up to do this? Just resave the post?
comment:7
colinwiseman
— 15 months ago
Ah yes. With 2272 posts I will need to write a script to do this :D Oh well the fun times of a programmer! But amazing that WordPress does that 301 automatically.
Thanks for all your time.
Colin
Replying to colinwiseman:
This sounds strange.
That line was added in [774] and exists there since WordPress 1.0.1 "Miles", so under normal circumstances URLs should not contain multiple hyphens.