buy viagra
Home » WordPress

WordPress replaces double and tripple hyphens (– or —)

9 January 2009 No Comment

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.

Solution

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. In my installation the file was here:

/wp-content/themes/[my-theme-name]/functions.php

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!

Leave your response!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.