• Resolved Gangz

    (@gangz)


    Hi,
    I often use double dash — but it gets converted into a single – em dash. How can i avoid this? I want the double dash to appear as it is instead of converting it to single dash.

    Thanks

Viewing 15 replies - 1 through 15 (of 15 total)
  • Moderator Jan Dembowski

    (@jdembowski)

    Forum Moderator and Brute Squad

    I had posted something like this in the past, but for my life couldn’t find it.

    Create an empty file in wp-content/plugins called un-en-dash.php and put these lines in it.

    <?php
    /*
    Plugin Name: Un-en-dash the Double Dash
    */
    add_filter( 'the_content' , 'mh_un_en_dash' , 50 );
    function mh_un_en_dash( $content ) {
            $content = str_replace( '& #8211;' , '--' , $content );
            return $content;
    }

    When you do paste this into that file, remove the space between & and #8211;.

    Or download it from this link https://pastebin.com/HWYGHDc7 which doesn’t have the space inserted.

    What’s changing the double dash to the en dash is the wptexturize filter applied to the content.

    That filter does lots so rather than disabling it, this plugin undoes the conversion. The ,50 ); means that it will run well after wptexturize() has done it’s work.

    This plugin will undo what wptexturize did to the double-dash only.

    Thread Starter Gangz

    (@gangz)

    Thanks Jan. That helps.

    Lemme ask u a very silly question. I’m new to wordpress and i don’t know how to install manual plugin. I hosted my site in bluehost and it had integrated wordpress application. I’ve installed the plugin available in worpress but don’t know how to install manual plugin. I read the below:
    Download your WordPress Plugin to your desktop.
    If downloaded as a zip archive, extract the Plugin folder to your desktop.
    Read through the “readme” file thoroughly to insure you follow the installation instructions.
    With your FTP program, upload the Plugin folder to the wp-content/plugins folder in your WordPress directory online.
    Go to Plugins screen and find the newly uploaded Plugin in the list.
    Click Activate Plugin to activate it.

    Where can I find wp-content/plugins folder to upload the plugin?

    Thanks

    Moderator Jan Dembowski

    (@jdembowski)

    Forum Moderator and Brute Squad

    I’m not familiar with Bluehost, so I’ll just give you the generic solution for a PC.

    – Download the file via https://pastebin.com/download.php?i=HWYGHDc7 and save it to your hard drive. It’ll save as un-en-dash.php.txt.

    – Rename the file un-en-dash.php.txt to un-en-dash.php (remove the .txt extension). If you are using Windows you’ll get a warning about changing the extension, don’t worry about that.

    – Using a zip archiver, create a new zip file and drop that un-en-dash.php file into it. I use 7zip.

    – Upload the new zip file via WordPress.

    https://your-wordpress-url/wp-admin/plugin-install.php?tab=upload

    – After it’s uploaded via WordPress you can activate it.

    If you create the zip file successfully, then that’ll work. You’ll be using WordPress to upload and install that plugin.

    You can probably just FTP to your server and locate the wp-content/plugins directory which would be easiest. You would just need to upload the un-en-dash.php file but again, I’m not familiar with Bluehost.

    Thread Starter Gangz

    (@gangz)

    Jan, Once again thanks a lot.

    I uploaded that plugin thru FTP and i’m able to see that plugin in my worpress an also activated it. But still i don’t see the issue resolved. Need some more help.
    Here how it looks .. ofcourse with no space btwn & and #8211
    <?php
    /*
    Plugin Name: Un-en-dash the Double Dash
    */
    add_filter( ‘the_content’ , ‘mh_un_en_dash’ , 50 );
    function mh_un_en_dash( $content ) {
    $content = str_replace( ‘& #8211;’ , ‘–‘, $content );
    return $content;
    }

    Moderator Jan Dembowski

    (@jdembowski)

    Forum Moderator and Brute Squad

    Can you provide a link? I used the & #8211; because that’s what the HTML source showed me on my test installation. Using that plugin converted it back for me.

    But I may have a different HTML code than is being used by your WordPress installation, so the substitution that plugin is making won’t change anything.

    Thread Starter Gangz

    (@gangz)

    Jan,
    Here is the link
    https://www.gangzonline.com/2012/02/06/chords-of-tum-se-hi/

    The 3rd pattern |D–U——| .. Between D & U their r 2 hyphens whereas after U their are 4 hyphens. Well with ur code atleast btwn D & U their r 2 hyphens but after U their shud be 4 which has reduced to 2.
    Thsi is how it shud look (no space in btwn but)
    |D – – U – – – -|

    Moderator Jan Dembowski

    (@jdembowski)

    Forum Moderator and Brute Squad

    Got it I think.

    So |D--U& #8212;-| should be |D - - U - - - -|, so add another line after the & $8211 line.

    <?php
    /*
    Plugin Name: Un-en-dash the Double Dash
    */
    add_filter( 'the_content' , 'mh_un_en_dash' , 50 );
    function mh_un_en_dash( $content ) {
            $content = str_replace( '& #8211;' , '--' , $content );
            $content = str_replace( '& #8212;' , '---' , $content );
            return $content;
    }

    Less the space of course. See if that does it.

    Thread Starter Gangz

    (@gangz)

    You r the man. The issue is completely fixed. Thanks much for your help.

    Btwn, Do I need to keep on adding lines if suppose their are 6 hyphens or 8 hyphens?

    Moderator Jan Dembowski

    (@jdembowski)

    Forum Moderator and Brute Squad

    Btwn, Do I need to keep on adding lines if suppose their are 6 hyphens or 8 hyphens?

    *Looks at wp-includes/formatting.php for wptexturize() and thinks “Gee, I should have remembered and look there yesterday.”*

    Nope! The only two dash conversions are the ‘en dash’ and the ’em dash’ or & #8211 and & #8212.

    You’re good to go. But before you leave could you mark this one resolved? It’s for future generations of chord readers. ??

    Thread Starter Gangz

    (@gangz)

    Thanks for confirming Jan. And i marked this as resolved ??

    Could just the function part be added to functions.php in a child theme or in my userfunctions file in MU plugins folder? thx

    Thread Starter Gangz

    (@gangz)

    Jan … help needed again.

    The issue is not resolved yet. Fixing that resulted in one another issue.

    If u look at this page
    https://www.gangzonline.com/2012/02/05/guitar-chords-of-jeene-ke-ishare-phir-milenge/

    suppose their are 8 dashes .. the 1st dash results in 2 dashes and the second one in 1 dash .. theirs an extra dash showing up. If u check the post in the link .. u’ll come to see that their are 2 dashes near by and then one dash .. the 2 dash is actually 1 dash .. i don’t know how dat one dash is converted to 2 dashes.

    Appreciare ur help. Thanks

    Moderator Jan Dembowski

    (@jdembowski)

    Forum Moderator and Brute Squad

    Could just the function part be added to functions.php in a child theme or in my userfunctions file in MU plugins folder? thx

    Either would work. Putting it in your theme’s functions.php file would mean you wouldn’t have to activate any plugin. It would only work when you have that theme active.

    With mu-plugins it would get automatically activated.

    The issue is not resolved yet. Fixing that resulted in one another issue.

    I can’t see it but I may have just missed it.

    Try this: create another plugin file called remove-wptexturize.php and put that into wp-content/plugins

    <?php
    /*
    Plugin Name: Remove the wptexturize filter
    */
    remove_filter( 'the_title' , 'wptexturize'  );
    remove_filter( 'the_content' , 'wptexturize' );
    remove_filter( 'the_excerpt' , 'wptexturize' );
    remove_filter( 'comment_text' , 'wptexturize' );
    remove_filter( 'list_cats' , 'wptexturize' );

    Deactivate the old plugin and activate this new one. This one will remove the filter from your post title, content, texcerpts, comment text, and category lists.

    That’s pretty much it. See it that fixes it.

    Thread Starter Gangz

    (@gangz)

    Ah ha .. the issue seem to be resolved now .. check now
    https://www.gangzonline.com/2012/01/15/guitar-chords-of-jeene-ke-ishare-phir-milenge/

    Best solution I found is to
    “comment out the first four elements of both arrays (in wordpress/wp-includes/formatting.php), so that it looks like this:

    $static_characters = array_merge(array( /* ‘—’, ‘ — ‘, ‘–’, ‘xn–’, */ ‘…’, ‘“’, ‘\’s’, ‘\’\’‘, ‘ ?’), $cockney);
    $static_replacements = array_merge(array(/* ‘—’, ‘ — ‘, ‘–’, ‘xn--’, */ ‘…’, ‘“’, ‘’s’, ‘”’, ‘ ™’), $cockneyreplace);”

    Check this blog:
    https://blog.paulbetts.org/index.php/2007/06/01/stop-wordpress-from-turning-double-dash-into-long-dash/
    it is working best for me and it is retroactive, no need to edit anything from before. Cheers.

Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘Issue with double dash’ is closed to new replies.