Reputation: 1037
In my basic Wordpress editor I have an article with html-code like this:
<h4><b>Hello!</h4>
<p> </p>
<p> </p>
<p>my text</p>
When that article page is loaded I always see only this:
<h4><b>Hello!</h4>
<p>my text</p>
How can I force WordPress to stop removing empty p
tags?
I have tried two methods and neither one worked:
1.I tried to add such lines to 'functions.php' of my theme:
remove_filter( 'the_excerpt', 'wpautop' );
remove_filter( 'the_content', 'wpautop' );
2.I tried to add slashes to all add_filter( 'the_excerpt', 'wpautop' );
in 'wp-includes/default-filters.php'.
None of these helped. Any ideas how to solve my problem?
Upvotes: 2
Views: 7133
Reputation: 135
Found here, use <b> </b>
to preserve the whitespace. As they state, it's hacky but it works.
Upvotes: 0
Reputation: 67778
I am using the "TinyMCE Advanced" plugin ( https://wordpress.org/plugins/tinymce-advanced/) to prevent "automatic handling" of <p>
tags in the editor.
That way I see the <p>
tags which are automatically created in "visual mode" also in the "text mode" tab and can change back and forth between the two modes without loosing any <p>
tags, including those which only contain a
entity and therefore create an empty line.
Upvotes: 0
Reputation: 2960
There are several options to not lose <p> </p>
.
Use only text editor: every time you're switching from Text
editor to Visual
you'll lose changes.
Use filter:
function prevent_deleting_pTags($init){
$init['wpautop'] = false;
return $init;
}
add_filter('tiny_mce_before_init', 'prevent_deleting_pTags');
Code goes to functions.php
file of your active theme.
Add some id/class/data-
to your p
tag:
<p class="my_class"> </p>
<p id="my_id"> </p>
<p data-save="my_save"> </p>
Upvotes: 3
Reputation: 204
This is due to the way your theme handles empty paragraphs. If the extra paragraphs are for spacing, the best thing to do would be to add a css id or class to the last paragraph and add the proper spacing with margin or padding.
I wouldn't add empty paragraphs so I have never had this problem, however I have seen some themes that automatically remove the <p>
and </p>
if the paragraph does not have a class or id. You could try the following to force WordPress to leave the paragraphs as is:
<h4><b>Hello!</h4>
<p class="blank"> </p>
<p class="blank"> </p>
<p class="texthere">my text</p>
Also, that <b>
has to be closed eventually...
Upvotes: 0