Hyphens and dashes in WordPress
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
InputOutputResultNote-
–en dashaloneword-word
word-wordhyphensurrounded by lettersword - word
word – worden dashbetween words with spacesword- word
word- wordhyphenspace afterword -word
word -wordhyphenspace before5-5
5-5hyphenbetween digits5 - 5
5 – 5en dashbetween digits with spacesDouble hyphens
InputOutputResultNote--
—em dashaloneword--word
word–worden dashsurrounded by lettersword -- word
word — wordem dashbetween words with spacesword-- word
word– worden dashspace afterword --word
word –worden dashspace before5--5
5–5en dashbetween digits5 -- 5
5 — 5em dashbetween digits with spacesTriple hyphens
InputOutputResultNote---
—em dashaloneword---word
word—wordem dashsurrounded by lettersword --- word
word — wordem dashbetween words with spaces5---5
5—5em dashbetween digits5 --- 5
5 — 5em dashbetween digits with spaceshttps://rene.seindal.dk/2024/05/02/hyphens-and-dashes-in-wordpress/
@blog Dashing en and em dashes.