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

admin2025-06-05  1

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.

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.

Share Improve this question edited Sep 24, 2014 at 4:01 Mark Kaplun 23.8k7 gold badges43 silver badges65 bronze badges asked Sep 24, 2014 at 3:36 sunsam7sunsam7 111 gold badge1 silver badge2 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 4

An ugly workaround I have always used in WordPress to add spaces is use <b>&nbsp;</b>

It's ugly, but it works.

//[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:

&nbsp;

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

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1749068485a316079.html

最新回复(0)