Reputation: 4047
Is there a way to prevent WP from removing br and p tags from posts or pages ?
so far I've added remove_filter('the_content', 'wpautop');
to my functions.php
file which completely disables formatting.
However when i edit a post or page, and in the HTML editor add br or p tags then switch back to visual mod the br/p tags that i added get removed.
Is there a way to prevent this ?
Upvotes: 4
Views: 15789
Reputation: 1768
It is not really a solution but a workaround: write your <p>
tags like this:
<p dir="ltr">something</p>
This way they are preserved when switching from editors. You can apply this to any text tag. Here you can read about the dir
attribute: http://www.w3.org/TR/html401/struct/dirlang.html
I have noticed that if you try to do the same with <br>
tags, when you swicht editors WP has replaced <br>
with a
. To prevent that, br
tags can be written like this:
<br class="blank" />
I am also looking for a definitive solution for this issue and it seems there is none yet, not even with the new Wordpress 3.6 release. Please if anyone knows a better solution I'll be so glad!
Upvotes: 16
Reputation: 917
Try the below code, in your functions.php,
function stop_removing_tags(){
remove_filter('the_content', 'wpautop');
}
add_action('init', 'stop_removing_tags');
Code Not Tested ...
Upvotes: 1