I’ve often been uncertain about what WordPress does with one or more hyphens in various contexts, and even looking at the code of wptexturize
is that useful — not all code is poetry.
One or more hyphens can produce a single hyphen (-), an en dash (–) or an em dash (—), but it’s not entirely straightforward.
TL;DR
A single hyphen becomes an en-dash if surrounded by spaces. Otherwise, it remains a hyphen.
Double hyphens become an em-dash if surrounded by spaces. Otherwise, they become an en-dash.
Triple hyphens always become an em-dash.
Common usage
Number ranges with en-dashes require double hyphens, as in 5–6. Otherwise, you’ll get a hyphen, like 5-6.
Em-dashes used as punctuation—normally without any spaces around—need to be entered as triple hyphens. If used with spaces around — which is not the common usage, however — double or triple hyphens work the same.
See — for example — How to Use Em Dashes (—), En Dashes (–), and Hyphens (-) on Merriam-Webster.
Test tables
Single hyphens
Input | Output | Result | Note |
---|---|---|---|
- | – | en dash | alone |
word-word | word-word | hyphen | surrounded by letters |
word - word | word – word | en dash | between words with spaces |
word- word | word- word | hyphen | space after |
word -word | word -word | hyphen | space before |
5-5 | 5-5 | hyphen | between digits |
5 - 5 | 5 – 5 | en dash | between digits with spaces |
Double hyphens
Input | Output | Result | Note |
---|---|---|---|
-- | — | em dash | alone |
word--word | word–word | en dash | surrounded by letters |
word -- word | word — word | em dash | between words with spaces |
word-- word | word– word | en dash | space after |
word --word | word –word | en dash | space before |
5--5 | 5–5 | en dash | between digits |
5 -- 5 | 5 — 5 | em dash | between digits with spaces |
Triple hyphens
Input | Output | Result | Note |
---|---|---|---|
--- | — | em dash | alone |
word---word | word—word | em dash | surrounded by letters |
word --- word | word — word | em dash | between words with spaces |
5---5 | 5—5 | em dash | between digits |
5 --- 5 | 5 — 5 | em dash | between digits with spaces |
Leave a Reply