How do I stop the editor from stripping my <p>
tags and “empty (& nbsp;)” divs on pages?
Since @scribu asked for a sample code here it is:
Input:
<p>text</p>
<div> </div>
Output:
text
How do I stop the editor from stripping my <p>
tags and “empty (& nbsp;)” divs on pages?
Since @scribu asked for a sample code here it is:
Input:
<p>text</p>
<div> </div>
Output:
text
You must be logged in to post a comment.
I had problems with TinyMCE Advanced. I struggled with this for a while. Finally discovered a simple solution – Use Shortcodes!
Place this code into functions.php and enter [br] wherever you want a br tag to appear.
1) Try a few different plugins that disable formatting and stop WP’s built-in stripping of extra paragraphs and whitespace: http://wordpress.org/extend/plugins/search.php?q=formatting&sort=
2) You can fool WP into adding a paragraph break by using
<b> <b/>
in the html editor. It’s a non-breaking space in<b>
tags. You won’t be able to see it in the visual editor, so add it in the htnl editor. It’s ugly, but it works without needing to fully disable formatting.3) You can also do this in functions.php and then wrap the text you don’t want formated with
<!-- noformat on -->
and<!-- noformat off -->
tags.I know this is a fairly old forum…I’ve come across many on this issue of visual editor stripping tags when switiching tabs…I simple followed this link: http://rubayathasan.com/reviews/enabling-line-break-in-wordpress/#comment-1349250
and installed TinyMCE Advanced…all is working like a charm and I now have more features to be able to add to my visual editor.
Add in your
functions.php
But you have to add no
<p>
and<br/>
manually. These tags are not saved in the database.It’s an older question, but this might help you or someone else for a part:
This adds the paragraph tags before saving. And of course the editor still understands how to process it 😉
It can’t help you with
, but you could ask yourself if they are necessary and maybe you can solve that with css? Just trying to help. Or use the hack (<b> <b/>
) explained by @markratledgeBit of a necro, but for the
<p>
tag you can add a class or perhaps another property.e.g.
<p class="nothing-relevant">Foo</p>
will not be stripped (using Gutenberg).
I’ve found that if you attach a class to your paragraph tag, wordpress won’t remove it. You don’t even have to have any CSS for the class.