Makin’ Those Double Dashes Show in WordPress 2.8.x

by kriggins on December 5, 2009

in Tips, Writing

If you do any sort of technical writing on WordPress, you have likely run into the wonderful little quirk of it turning your lovingly formatted double dashes '--' into singe em dashes. Rather annoying.

To add insult to injury, the silly thing shows them as double dashes in the editor, but then renders them as em dashes when viewing the post, making it next to impossible to know what is going on.

I thought I had it fixed at one time, but apparently the behavior snuck back in. I finally got tired of writing "those are two dashes not one" all over the place and went in search of a better answer.

Lo and behold I found one. Peter Cooper had the same problem and figured out how to take care of it. You can see his post here. His is for WordPress 2.5, but it also works for 2.8.x. I have combined his directions along with some info from the comments on his post here just in case I need it again and can't find it 🙂

Update: After I posted this, one of my friends on twitter, Chris John Riley, offered up another option. Add an HTML comment with just a space between the dashes. You will have to do this in the HTML view instead of Visual view of the editor. It will look like this:

-<!-- -->-

As I said to him, definitely less intrusive, although, with the method below, I just double dash away and don't worry about it 🙂

Thanks Chris!

WordPress has a built-in function called wp_texturize(). The purpose of this function is to make your beautiful prose lovely to look at too. 🙂 Unfortunately, for those of use who do technical writing, it also completely mucks up some of our stuff.

To stop this from happening you need to edit the functions.php file in your current theme. This file is in your wp-content/themes/<your theme> directory.

All you have to do is add the following three lines to the end of the functions.php file.

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

These lines tell WordPress to quit mucking with punctuation in the main content, comments and rss feed. If you want to allow it to do so in any of the three, just omit the appropriate line.

Here is my functions.php file for reference:

<?php
  // Current version of K2
  define('K2_CURRENT', 'hidden cause you don't need to know');

  // Is this MU or no?
  define('K2_MU', (isset($wpmu_version) or (strpos($wp_version, 'wordpress-mu') !== false)));

  // Are we using K2 Styles?
  define('K2_CHILD_THEME', get_stylesheet() != get_template());

  // WordPress compatibility
  @define( 'WP_CONTENT_DIR', ABSPATH . 'wp-content' );
  @define( 'WP_CONTENT_URL', get_option('siteurl') . '/wp-content' )

  /* Blast you red baron! Initialise the k2 system */
  require_once(TEMPLATEPATH . '/app/classes/k2.php');
  K2::init();
?>
<?php remove_filter('the_content', 'wptexturize'); ?>
<?php remove_filter('comment_text', 'wptexturize'); ?>
<?php remove_filter('the_rss_content', 'wptexturize'); ?>

One final note, this also affects all other punctuation changes, so you won't get smart quotes, etc.

-Kevin

{ 0 comments… add one now }

Leave a Comment

Previous post:

Next post: