Skip to content

Instantly share code, notes, and snippets.

@robinsloan
Last active January 10, 2016 23:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robinsloan/caa5fa173f540d2a0337 to your computer and use it in GitHub Desktop.
Save robinsloan/caa5fa173f540d2a0337 to your computer and use it in GitHub Desktop.
// for functions.php
function em_dash_filter($content) {
# add to css: .nobr { whitespace: nowrap; }
return preg_replace('/(\w+)(—|&mdash;|&#8212;)/', '<span class="nobr">$1$2</span><wbr>', $content);
}
add_filter( "the_content", "em_dash_filter" );
@jimray
Copy link

jimray commented Jan 9, 2016

Not to be Mr. Semantics Guy...

So, nobr is non-standard (it isn't even tracked by caniuse!) and future support is possibly iffy. A span tag with a class="nobr" and a whitespace: nowrap; rule would accomplish the same thing and work everywhere, forever!

More here!

Honestly, though, browsers should do this by default. I mean really.

@robinsloan
Copy link
Author

I like things that work everywhere, forever! Changed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment