Stop editor from removing tags and replacing them with nbsp

I have done extended research and found the answer – I am now using a hook on ‘tiny_mce_before_init’.

Based on other answers (special thanks to answer #2 @Chip Bennett), I have used the following code in my functions.php to secure the paragraph breaks (in the editor HTML mode they show as &nbsp but become paragraphs on the front-end):

function tinymce_config_59772( $init ) {
   // Don't remove line breaks
   $init['remove_linebreaks'] = false; 
   // Convert newline characters to BR tags
   $init['convert_newlines_to_brs'] = true; 
   // Do not remove redundant BR tags
   $init['remove_redundant_brs'] = false;

   // Pass $init back to WordPress
   return $init;
}
add_filter('tiny_mce_before_init', 'tinymce_config_59772');

You can find on the tinyMCE site the different possible configurations.

Leave a Comment

error code: 523