Prevent WordPress From Converting Double Hyphen (‐‐) Into Dash (–)

Prevent WordPress From Converting Double Hyphen Into Dash

This short post covers how to stop WordPress from converting double hyphens (‐‐) to single long dash (–)

Usually I see -- referred to as double dash, and I’m not sure which if I’m correct in calling them hyphens. Nevertheless, I hope this post helps you and please correct me in the comments, if you know the proper way of calling them.

I’ve encountered this issue most often when trying to render text in syntax highlighters, or when using the WordPress Classic Editor in Text Mode.

The solutions I use are not optimal, most likely, but have worked for me and I think and are user friendly, as they don’t require you to create a plugin yourself or edit WordPress core files.

I consider them as a temporary solution to be able to get on with your work instead of spending time finding the ideal fix.

1. Using the Hyphen HTML Code

This is the easiest way.

You just have to use the Hyphen HTML Code in your HTML (I’m using the WordPress Classic Editor, and write directly in Text Mode, and not Visual).

It also renders correctly in Post Titles and Excerpts.

You can simply write ‐‐ or ‐‐ and WordPress will render ‐‐

‐ is more persistent than ‐ (If I try to highlight it with the dark blue background, WordPress renders it as a hyphen)

2. Using Raw HTML Free WordPress Plugin

I use the Raw HTML plugin by By Janis Elsts from the WordPress Plugin Repository, and the Classic WordPress Editor (I’m not sure if there’s a different behavior in Gutenberg), and Enlighter Plugin for syntax highlighting.

After you install it, you can just wrap any part of your post in the [raw]...[/raw] tags.

In my case, to prevent hyphen conversion into dash, when writing code. The way I prevent with this plugin is as follows:

sudo firewall-cmd [raw]--[/raw]reload

sudo firewall-cmd --reload

..instead of..

sudo firewall-cmd --reload

sudo firewall-cmd – reload

Some of the solutions that I’ve frequently encountered in most Google search results

Not Using – Removing the wptexturize() filter

Why I’m not doing this: I’m not very knowledgeable in WordPress, but from the WordPress Code Reference on wptexturize where it says Replaces common plain text characters with formatted entities, if you scroll a bit on that page you can see that disabling the filter will prevent WordPress from formatting other plain text characters that I may still want to be formatted.

wptexturize() list of formatted HTML entities

So I can’t see how this solution would be a proper fix for this matter.

Not Using – Editing the wp-includes/formatting.php file

Why I’m not doing this: Again, I’m not a WordPress developer, but if I edit that file and it works, and then I update WordPress, I suspect that file may be updated and all my changes lost.

In the Updating WordPress page on they start off with a warning:

Additional Notes & Updates

In some cases I’ve seen that the double hyphen is kept intact without any of the listed workarounds, however I haven’t been able to pinpoint the exact scenarios when this happens. Perhaps someone can help? Any solutions are more than welcome.

I’ll try to keep this article updated.


Again, I’m not saying these are the best solutions/workarounds, but they’ve worked for me since I first encountered the hyphen conversion issue.

I’m sure there must be others suggesting better fixes that I may have overlooked.

If you have feedback, criticism, or a better solution then I’d love to hear from you.

Feel free to let me know in the comments or by contact us.

Leave a Reply

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