How to use a Non-Breaking Space in WordPress

A non-breaking space allows you to add a space between two words that prevents an automatic line break (line wrap) at its position.

They’re commonly used where amounts, such as dollars are separated using a space or when typing a brand name.

When using Microsoft Word it’s as easy as typing Ctrl + Shift + Space – but it’s not at easy in an HTML WYSIWYG editor such as in WordPress.

To use non-breaking spaces in WordPress you first need to add the following code to your theme’s functions.php file, below the opening <?php line

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

You can then follow the steps below to insert a non-breaking space into a WordPress post.

  1. With the post open, click on the ‘Text’ tab at the top of the WYSIWYG editor
  2. WordPress-NonBreakingSpace1
  3. Locate where you need the non-breaking space, it’ll be harder to read since it’s the source code – not the formatted text.
  4. Once you’ve located the place, remove the normal space and add the following code
  5.  &nbsp;
  6. BEFORE
  7. WordPress-NonBreakingSpace2
  8. AFTER
  9. WordPress-NonBreakingSpace3
  10. You can nowclick on the ‘Visual’ tab to return to the visual editor
  11. Click Publish/Update to save the changes.