Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Preventing wp from removing br and p tags

Tags:

html

wordpress

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 ?

like image 327
Neta Meta Avatar asked Dec 05 '22 13:12

Neta Meta


1 Answers

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 &nbsp;. 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!

like image 82
ithil Avatar answered Dec 22 '22 00:12

ithil