3

Thanks to the German language, I happen to have some really long words in my WordPress 5.4.1 content. I need to decide where exactly to hyphenate, as the standard hyphenation is dumb.

If I enter Wachstums­förderung in the Gutenberg block editor in a headline (e.g. h2), I do not get the expected Wachstums-förderung in the website - it outputs Wachstums­förderung.
(This does work, though, in the page title, outside of the block editor)!

My web search yielded an open issue on GitHub: https://github.com/WordPress/gutenberg/issues/12872
It is open since Dec 2018 and nothing seems to happen soon :-/

Does anybody have an idea, how to solve that problem? (No, putting a hard dash is not an option.)

3
  • Maybe copy and pasting a soft-hyphen character might work? WordPress should store it and re-render it correctly, even if it might not encode it as an entity.
    – Rup
    May 14, 2020 at 11:38
  • Clever idea, @rup but I can't manage to copy it - I am not able to mark/select it in the browser :-/
    – jasie
    May 14, 2020 at 11:43
  • 1
    There are a lots of services where you can copy this character. Just google a little :) E.g. unicode-explorer.com/c/00AD
    – Lovor
    Feb 5, 2023 at 17:26

3 Answers 3

2

You can change the block to "edit as html" via "more options" and set the soft hyphen, then switch back to "Edit visualy".

3
  • This does not work, as TinyMCE is filtering out the ­ entity amongst others (in Gutenberg for example)
    – Larzan
    Jul 5, 2021 at 7:08
  • Do you have tested it? It's filtered out in the editor, but if you check the frontend you'll see that the ­ ist placed in html.
    – Buglover
    Jan 30, 2023 at 20:58
  • Confirm this works. This is the best option in my opinion. Hyphen always shows in editor, but only when needed on the frontend 20 hours ago
2

With the 'new' Gutenberg editor the previously working solution using the tiny_mce_before_init hook does not work anymore, but there is the possibility to define a new shortcode in your theme / plugin as a workaround.

Solution for Gutenberg

add_shortcode('shy', 'my_shy_shortcode');
function my_shy_shortcode($atts) {
    return '­';
}

This simply adds a new shortcode to WordPress with a ­ entity as output, so you can just write [shy] anywhere in your text and it will be translated to the HTML entity;

There is currently no 'cleaner' solution and it seems that none is planned, at least not before 5.8 (Github issue 1, issue 2)

Solution for the Classic Editor (no Gutenberg)

function override_mce_options($initArray) {
    $initArray['entities'] = 'shy';

    return $initArray;
}
add_filter('tiny_mce_before_init', 'override_mce_options');

This should prevent TinyMCE from filtering out the shy tag, for more information on how to fine-tune this and keep other entities as well read here: https://stackoverflow.com/a/29261339/826194

1

Here is a invisible soft hyphen for you to copy: "­".

Unlike the HTML entity ­ which gets filtered out the second time you edit your content, I am able to insert the invisible soft hyphen character. Unfortunately you can visually not tell when it's present. You can identify a invisible character because the cursor won't move when you hit arrow key.

I am using macOS and configured the [fn] key on my keyboard to show the character/emoji picker. There you can search for "soft hyphen"; it appears as a normal hyphen, but when you double click it, it will be inserted into you document.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.