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


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

It's ugly, but it works.

  • Thank you very much!You're right.But I still want to find some way to keep spaces without using html code.
    – sunsam7
    Commented Sep 24, 2014 at 8:57
//[nbsp] shortcode
function nbsp_shortcode( $atts, $content = null ) {
$content = '&nbsp';
return $content;
add_shortcode( 'nbsp', 'nbsp_shortcode' );

Then call it like this:


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

  • Hi Nathaniel, welcome to WPSE and thanks for your answer. Link-only answers are discouraged as they can change over time. You can use the link to provide context, but could you edit your answer to include the relevant information & code for the [nbsp] workaround? Thanks!
    – Tim Malone
    Commented Jul 28, 2016 at 20:41
  • 1
    Sure I just didn't want to plagiarise their information, and I doubt wordpress org's url will change, but will do no worries. Commented Jul 29, 2016 at 12:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.