最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

functions - Stop turning small dashes into longer ones

matteradmin10PV0评论

When I write my site's title, description, posts, pages, or a taxonomy description, small dashes - are turned into longer, uglier ones –.

Is there some way to stop this from happening? Can I put some sort of function in my functions.php? Any ideas?

When I write my site's title, description, posts, pages, or a taxonomy description, small dashes - are turned into longer, uglier ones –.

Is there some way to stop this from happening? Can I put some sort of function in my functions.php? Any ideas?

Share Improve this question edited Dec 9, 2012 at 8:27 shea 5,6724 gold badges39 silver badges62 bronze badges asked Dec 9, 2012 at 6:07 webmasterswebmasters 3112 gold badges7 silver badges21 bronze badges 0
Add a comment  | 

2 Answers 2

Reset to default 1

- is a hyphen or minus, not a dash. Converting it to an en dash is actually the correct thing to do from a typographical standpoint.

http://en.wikipedia/wiki/Hyphen-minus

Typography is one of those deep-read kind of ideas, but the bottom line is that you think the hyphen minus is the correct character to use because of limitations in early typewriters. The correct character to use in most all the instances where you type the minus sign, from a typesetting and printing (and now, web) point of view is actually the en dash.

But if you really want to use incorrect typography, then bungeshea's approach above will work, or you can remove the wptexturize filter from the_content. The wptexturize function corrects this common typographical mistake, as well as fixing quotes, apostrophes, primes and double primes, dashes, whole bunch of other stuff. Basically it transforms what you type into the correct typography for it.

The transformation happens in the wptexturize() function. It turns a regular dash (-) into an en dash (–). The function translates the en dash using the _x() function, which in turn uses the gettext_with_context filter. We can hook into this filter to return a regular dash instead of an en dash:

add_filter( 'gettext_with_context', 'wpse_75445_use_pretty_dash', 10, 2 );

function wpse_75445_use_pretty_dash( $text, $context ) {
    if ( $text == '–' && $context == 'en dash' )
        $text = '-'
    return $text;
}

However, as explained in Otto's answer, it's typographically correct to use an en dash instead of a hyphen/minus sign. But it is your site, so whatever works for you and your users.

Post a comment

comment list (0)

  1. No comments so far