How to keep   non-breaking spaces in the visual editor?

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 Comment