Make WordPress Core

Opened 5 years ago

Last modified 3 months ago

#10792 new enhancement

Forward Slashes convert to hyphens in post slugs

Reported by: alxndr Owned by:
Milestone: Future Release Priority: low
Severity: trivial Version: 3.8
Component: Formatting Keywords: has-patch needs-unit-tests
Focuses: Cc:


In slugs for taxonomies or post permalinks, slashes (/\) and ampersands (&) are stripped out. More useful URLs would be created by turning slashes into hyphens, and ampersands into the word "and".


"songs by Lennon/McCartney"
expected slug: "songs-by-lennon-mccartney"
actual slug: "songs-by-lennonmccartney"

"Us & Them"
expected slug: "us-and-them"
actual slug: "us-them"

Attachments (2)

slug-slash-ampersand.2.patch (594 bytes) - added by alxndr 5 years ago.
replaces slashes with hyphens in post title slugs and taxonomy term slugs; replaces ampersands with "and" and "&c" with "etc" in post title slugs
10792-forward-slash-to-hyphen.diff (467 bytes) - added by GhostToast 3 months ago.
convert forward slash to hyphen

Download all attachments as: .zip

Change History (18)

alxndr5 years ago

replaces slashes with hyphens in post title slugs and taxonomy term slugs; replaces ampersands with "and" and "&c" with "etc" in post title slugs

comment:1 alxndr5 years ago

This patch doesn't extend the ampersand fix to category/tag slugs (but the slash fix works). Perhaps ampersands are being stripped out before the title hits sanitize_title_with_dashes() ? I haven't dug around enough yet...

comment:2 scribu5 years ago

  • Milestone changed from Unassigned to Future Release

Agree with the slash replacement.

Don't agree with the & replacement due to internationalization problems: if you write a blog in french, you won't want '&' to be replaced with 'and'.

comment:3 alxndr5 years ago

Oh right. ('and') perhaps?

comment:4 alxndr5 years ago

Arg... that should have been


comment:5 SergeyBiryukov3 years ago

  • Component changed from General to Formatting
  • Keywords has-patch added
  • Milestone changed from Future Release to 3.3

Related: #10823

comment:6 SergeyBiryukov3 years ago

  • Keywords needs-refresh added

comment:7 follow-up: SergeyBiryukov3 years ago

We already have __(' and ') string in .pot from wp_sprintf_l(), so we probably can use it here.

comment:8 SergeyBiryukov3 years ago

  • Milestone changed from 3.3 to Future Release

comment:9 blogbuzz2 years ago

How can I force to use the slash in the url? I want to use a slash in my post url, but when I save my custom slug in the post editor it gets stripped out. Should be possible cause there are situations were you want to use slashes.

Last edited 2 years ago by blogbuzz (previous) (diff)

comment:11 GhostToast3 months ago

Any traction on this? Particularly involving the forward slash "/" not being converted into a dash/hyphen "-", I have long thought this behavior odd, as it defaults to slugs which are unreadable. Are there any instances where hyphen would not be desired in place of a slash?

comment:12 in reply to: ↑ 7 F J Kaiser3 months ago

Replying to SergeyBiryukov:

We already have __(' and ') string in .pot from wp_sprintf_l(), so we probably can use it here.

I'm not too sure how someone would react if they got a site where the internal language is defined to be Korean, but the post is written in English. Example Title:

Me & her spent a wonderful weekend together

URL after the patch converted & to __('and') and therefor to Korean:


Very sure that it would be better to simply replace an ampersand with a dash.

Last edited 3 months ago by F J Kaiser (previous) (diff)

GhostToast3 months ago

convert forward slash to hyphen

comment:13 GhostToast3 months ago

  • Keywords needs-testing added; needs-refresh removed
  • Version set to 3.8

comment:14 GhostToast3 months ago

  • Summary changed from ampersands and slashes stripped out of slugs to Forward Slashes convert to hyphens in post slugs

comment:15 nacin3 months ago

  • Keywords needs-unit-tests added; needs-testing removed

I agree with the slash (only). I can never remember how this works — is this safe to change without affecting existing slugs? Seems like.

Unit tests would be great.

comment:16 GhostToast3 months ago

I have tested various configurations of saving/pending/draft/publish and have found the following:

  • If a title Computers/Robots was saved prior to my patch, it's slug computersrobots remains unchanged despite various publish/unpublish status changes (unless intentionally edited).
  • If a title Computers/Robots is pending for publish, and auto-slug generation occurs, computers-robots is assigned. Manually editing this slug back to computersrobots if desired, will be honored, despite any publish/save/unpublish status changes.
  • If a title Computers/Robots has been published with the patch, it's slug becomes computers-robots until manually edited.

This all seems to be working as intended.

Last edited 3 months ago by GhostToast (previous) (diff)
Note: See TracTickets for help on using tickets.