mastodon.social is one of the many independent Mastodon servers you can use to participate in the fediverse.
The original server operated by the Mastodon gGmbH non-profit

Administered by:

Server stats:

279K
active users

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-wordword-wordhyphensurrounded by lettersword - wordword – worden dashbetween words with spacesword- wordword- wordhyphenspace afterword -wordword -wordhyphenspace before5-55-5hyphenbetween digits5 - 55 – 5en dashbetween digits with spaces

Double hyphens

InputOutputResultNote--—em dashaloneword--wordword–worden dashsurrounded by lettersword -- wordword — wordem dashbetween words with spacesword-- wordword– worden dashspace afterword --wordword –worden dashspace before5--55–5en dashbetween digits5 -- 55 — 5em dashbetween digits with spaces

Triple hyphens

InputOutputResultNote---—em dashaloneword---wordword—wordem dashsurrounded by lettersword --- wordword — wordem dashbetween words with spaces5---55—5em dashbetween digits5 --- 55 — 5em dashbetween digits with spaces

#Wordpress #Writing

https://rene.seindal.dk/2024/05/02/hyphens-and-dashes-in-wordpress/

WordPress Developer Resourceswptexturize() | Function | WordPress Developer ResourcesReplaces common plain text characters with formatted entities.