Stop editor from removing <p> tags and replacing them with nbsp

When I enter content in posts/pages’ WYSIWYG editor, I do not get <p> when ending paragraphs, just &nbsps. If I manually place <p></p> in the HTML mode, they are stripped as soon as I switch to ‘visual’ mode.
This is repeated in several sites (I thought it was the theme but it isn’t).

I have read dozens of topics and answers, but none solve my problem.
I tried add/remove wpautop in my functions.php file but nothing helps.

Read More

I do not want to use a tinymce plugin.

Related posts

Leave a Reply

3 comments

  1. 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.

  2. you could also say that TinyMCE is integrated with WordPress and the HTML editor strips out some characters in favour &nbsp … this was originally for security and the belief that we didnt need <br> or <p> anymore