Double hyphen in Wordpress

Apr 9, 2012·
Julio Batista Silva
Julio Batista Silva
· 2 min read
blog Tutorial

Before moving to Octopress (and later to Hugo), this blog was written in Wordpress. Every time I posted a tutorial with commands that take double-dash options (for example: ls --all), Wordpress formatted the two consecutive hyphens (--) as a dash (—). That probably confused readers (e.g. ls --all), and it also meant the code could not simply be copied from the blog and pasted into a terminal.

We can change this setting directly in the Wordpress source code.

  1. Edit the static_characters array in the file wp-includes/formatting.php

    juliobor@box780 ~  $  vim www/blog/wp-includes/formatting.php
    

Before:

$static_characters = array_merge( array('---', ' -- ', '--', ' - ', 'xn–', '...', '``', '\'\'', ' (tm)'), $cockney );
$static_replacements = array_merge( array($em_dash, ' ' . $em_dash . ' ', $en_dash, ' ' . $en_dash . ' ', 'xn--', '…', $opening_quote, $closing_quote, ' ™'), $cockneyreplace );

After:

$static_characters = array_merge( array('------', ' ---- ', '----', ' - ', 'xn–', '...', '``', '\'\'', ' (tm)'), $cockney );
$static_replacements = array_merge( array($em_dash, ' ' . $em_dash . ' ', $en_dash, ' ' . $en_dash . ' ', 'xn--', '…', $opening_quote, $closing_quote, ' ™'), $cockneyreplace );

Now -- will come out as two small hyphens. If we want to insert a dash (—), we will have to type four hyphens in a row.

NOTE: Remember to do this after every Wordpress update.

Julio Batista Silva
Authors
Senior Cloud Developer

I’m a Brazilian computer engineer based in Germany, passionate about tech, science, photography, and languages.

I’ve been programming for about two decades already, exploring everything from mobile apps and web development to machine learning. These days I focus on cloud SRE and data engineering.

I volunteer in the open source and Python communities, helping organize PyCon DE and PyData Berlin, mentoring, and contributing with code and translations.

On my blog, I share Linux tips, setup guides, and personal notes I’ve written for future reference. I hope others find them helpful as well. The content is available in multiple languages.

Browse my gallery for some of my photography.

Away from the keyboard, you’ll find me at concerts, playing clarinet, cycling, scuba diving, or exploring new places, cultures, and cuisines.

Always happy to connect! 🙂

comments powered by Disqus