­ hyphenation not working in Gutenberg editor

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.)

Best Answer

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');

You may Also Like:

Leave a Comment