WordPress replaces double and triple hyphens (– or —)

Problem: The other day I was trying to type two hypens (–) in a post, and when I saved/published the post, WordPress reformatted the hypens to display as an ‘en dash‘ (–).

More Info: After some searching about, and some helpful info provided in the WordPress Codex, I found out about a WP function called ‘wptexturize’ which is applied each time a post is rendered. The function – which can be found in ‘wp-includes/formatting.php’ – replaces quite a few things, like ™ to ™ etc.

Fix: You could stop this happening a number of ways i.e. editing the function to stop it doing the replace altogether, or install a plugin that does it (maybe this one, haven’t tried it!). I decided to use WordPress’s remove_filter function to stop the reformatting taking place.

To do this, open the ‘functions.php’ file within your theme. If one does not exist, create it.

Add the following code to the bottom of the file, taking care not to end up with too many or too few <?php tags:

<?php
remove_filter('the_content', 'wptexturize');
remove_filter('the_title', 'wptexturize');
?>

Then save the file (or ‘update’ if you’re doing this via the theme editor in WP admin) and view your post. That should do it! (proof is here, you can only see those double and triple hyphens in this blog post title because I’ve just added the code above to this sites functions.php also!)

Leave a Reply

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