How to disable dash replacement in WordPress. AutoCorrect settings for characters and words in WordPress
March 28, 2019
Before each output of the text of the article, WordPress checks this text and can format it in accordance with its ideas of beauty. For example, in the text of the article, two dashes in a row will be replaced with one dash, three dashes in a row will also be replaced with one, a large dash can be replaced with a small one if, according to WordPress, it is used incorrectly (an example of incorrect use of a large dash is in the range, for example ‘In 2-3 days’).
For the overwhelming majority of webmasters, this simply does not matter, since the formatting affects, besides dashes, spaces, apostrophes (used not in all languages), single and double quotes (used not in all languages), therefore there are no problems with that for the most web masters.
Only one category was not lucky – those who write technical articles about programs with the command line interface, when you need to specify options. These are usually programs for Linux. So, in their articles, the type option --version turns into —version. In this form, the option becomes inoperative. There may be other examples where auto-replacement and automatic removal of characters is harmful.
In this post, I’ll show you how to disable two-dash auto-replace into one dash, and we’ll also find out where in WordPress you can set up word and character auto-change.
How to disable the replacement of two dashes into one
To disable the automatic replacement of dashes in WordPress, open the file wp-includes/formatting.php, find the lines there:
and delete them all.
The first line changes three dashes in a row to one big dash. The second changes two dashes in a row, followed by a space, on the big dash. The third line changes two dashes in a row to a small dash. The fourth, under certain conditions, changes a large dash to a small one.
Here is the code snippet from my article about the WordPress plugin, as a result of the automatic replacement, the text became like this (all short-codes are not functional):
After deleting the above lines, all the short-codes have taken their original form:
AutoCorrect words and characters in WordPress
In the same file (wp-includes/formatting.php), apostrophes and quotes are replaced, unnecessary spaces are removed. Sections of the code have comments, so you can navigate which line bothers you and delete it, so as not to perform the corresponding replacement.
Also in this file there is a function to replace the cockney – by analogy, you can make the replacement of words in the text on the fly. Although, perhaps, if it is not related to editing, then for this it is better to use some kind of plugin.
Since we edited the source file wp-includes/formatting.php, with every major update, and sometimes with minor updates of WordPress, all settings are reset – you have to do everything again. You may need to configure an automatic patcher.
If you have websites in different languages, then this file is identical for all of them, so you can make changes in one file and download it with overwriting to all sites, regardless of language.