I often add   between connecting words so they break down together to a new line in important text. Switching to visual tab then back to text tab removes these. What can I do to keep them and avoid TinyMCE removing them?

I found this but not sure how to apply it to WordPress: https://www.abeautifulsite.net/tinymce-removes-non-breaking-spaces

My ugly solutions would be using a different custom string between words__like__this then later replacing them to   in PHP, before display. Or just typing it on the visual tab, which translates to   but then converting them with PHP.

1 Answer
1

This seems to do it:

function allow_nbsp_in_tinymce( $mceInit ) {
    $mceInit['entities'] = '160,nbsp,38,amp,60,lt,62,gt';   
    $mceInit['entity_encoding'] = 'named';
    return $mceInit;
}
add_filter( 'tiny_mce_before_init', 'allow_nbsp_in_tinymce' );

Also see: https://www.tinymce.com/docs/configure/content-filtering/#entities

Any improvement suggestions?

Leave a Reply

Your email address will not be published. Required fields are marked *