6

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.

I do not want to use a tinymce plugin.

3 Answers 3

3

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.

1
  • 7
    function name shouldnt start with numbers. It throws error.
    – ewroman
    Commented Apr 21, 2014 at 19:31
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

7
  • oh how wrong they were....lol
    – Androliyah
    Commented Jul 26, 2012 at 21:18
  • @Aliyah I dont think they'll add it back again. It's been that way for years. FWIW ... I never knew CKEditor had been packaged for WordPress and I guess it is free?
    – Damien
    Commented Jul 26, 2012 at 21:46
  • Yea its in the WP plugins directory in the link I gave
    – Androliyah
    Commented Jul 26, 2012 at 21:49
  • 1
    wait a sec lol..is that your answer?
    – Androliyah
    Commented Jul 26, 2012 at 21:59
  • 1
    Same quality answers as the WP forum... eye roll
    – BAR
    Commented Nov 6, 2014 at 14:45
1

You can try the CKEditor

Wordpress CKEditor

4
  • @aliyah- isn't there some code we can use? I don't like using plugins, because you never know how they'll affect other things.
    – Nona Man
    Commented Jul 27, 2012 at 9:28
  • @NonaMan Not every plugin has adverse effects on the site. Try it out and see if it solves your problem. This is simply an enhanced WYSIWYG editor plugin. It may or may not solve your problem, never hurts to try. You can always disable it. I'm using it now and the site runs smoothly. It doesnt make any serious changes.
    – Androliyah
    Commented Jul 27, 2012 at 18:47
  • This works and provides the editor with the ability to keep the paragraph tags. Thankyou! I do wish someone can write a function that hooks onto the editor and changes the 'nbsp' to paragraph tags.
    – Nona Man
    Commented Jul 31, 2012 at 4:48
  • @NonaMan Me too lol
    – Androliyah
    Commented Aug 1, 2012 at 22:05

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.