WordPress and dashes (m-dash & n-dash)

This post is outdated as of WordPress 6.0. See the first comment.

I got you there, I too didn’t know there were n and m dashes “–” and “—“.

Anyways, the process of using one of these in my life was something like this:

  1. Search Google for “mdash”
  2. Use my eye scanning technique to find any dash which looks longer than usual
  4. life goes on

Tired of this repetitive process, I decided to replace an n/m dash with a hyphen (-), those looked unfamiliar and rather creepy ( -example-), so I changed my mind again and decided to use double hyphens (- -).

Surprise! WordPress turns automatically any 2 consecutive and uspaced hyphens into n-dashes and any 3 hyphens into m-dashes, like this see:

  • 2 dashes: —
  • 3 dashes: —

Well, it’s not that simple, so for those of you who really want to know the origin of things, check the wptexturize() function, especially around those lines.

If you don’t like this behavior, and your life depends on the hyphens remaining hyphens, you can use this small plugin:

Plugin Name: Remove the wptexturize filter
remove_filter( 'the_title' , 'wptexturize'  );
remove_filter( 'the_content' , 'wptexturize' );
remove_filter( 'the_excerpt' , 'wptexturize' );
remove_filter( 'comment_text' , 'wptexturize' );
remove_filter( 'list_cats' , 'wptexturize' );

Name the file as you want but make sure you place it under the wp-content/plugins directory and you enable the plugin in your awesome website dashboard.

2 thoughts on “WordPress and dashes (m-dash & n-dash)

Hi, just wanted to let you and others know that this is out of date. These are the transformations as of WordPress 6.0:

* One, single freestanding minus/hyphen sign in the editor is transformed into an n dash
* Two freestanding minus/hyphen signs are transformed into an m dash.
* A minus/hyphen sign sandwiched between non-whitespace characters remains a hyphen/minus sign.

Note that this mainly applies to paragraph blocks and the like, so e.g. a freestanding minus in a code block remains a minus.


Leave a Reply

Your email address will not be published. Required fields are marked *