How to stop editor removing space ( ) in the beginning of the paragraph

I use WordPress with TinyMCE in Chinese.

It needs double white spaces in the beginning of each paragraph. But the editor will automatically removing all spaces(white space and nbsp; code) in the beginning of the paragraph when I toggle the editor between WYSIWYG mode and HTML mode.

When I used WordPress 3.8, I could stop it doing this with these code

add_filter('tiny_mce_before_init', 'preserve_nbsp_chars');
function preserve_nbsp_chars($initArray) {
    $initArray['entities'] = $initArray['entities'].',160,nbsp';
    return $initArray;
}

The bad thing is it does not work after I updated WP to 4.0.

2 Answers
2

//[nbsp] shortcode
function nbsp_shortcode( $atts, $content = null ) {
$content="&nbsp";
return $content;
}
add_shortcode( 'nbsp', 'nbsp_shortcode' );

Then call it like this:

[nbsp]

Instead of:

 

Hat tip to this post on wordpress.org: https://wordpress.org/support/topic/prevent-nbsp-characters-from-getting-removed-by-the-visual-editor

Leave a Comment