WordPress wpautop issue

百般思念 提交于 2019-12-04 19:22:53

The easiest and simplest way to avoid wpauto issue is to understand how wpautop works,

Any plain text, or inline element that aren't wrap with block element will be automatically wrap with p. if element is block and doesn't have two line breaks inside it, it won't be wrap with P as well as the elements inside it, empty inline element will be strip and remove.

example

inline

<img src="blabal.jpg"> will be output <p><img src="blabal.jpg"></p>,

I am awesome will output <p>I am awesome</p>,

<span>Really?</span> will output <p><span>Really?</span></p>,

block

<div><img src="blabal.jpg"></div> will be output <div><img src="blabal.jpg"></div>,

<div>I am awesome</div> will output <div>I am awesome</div>,

<div><span>Really?</span></div> will output <div><span>Really?</span></div>,

<span></span> will output nothing, (empty inline elements will be removed.),

I really like wpautop, I never disable it, I just wrap any content with DIV if there's an element I don't want to have P, I also have a shortcode that avoids wpauto when element is inside, its helpful when you have a long ass content that wanted to avoid automatic p tag

Here's a fix/work-around I just found through experimentation. Give the <p> element an attribute (<p class>). It doesn't even have to have an actual value. WordPress seems to think that if it has an attribute, it's worth keeping. Furthermore, the attribute doesn't even have to be an actual HTML attribute. For example, <p data-please-work> seems to work just fine. I'm not saying I necessarily recommend doing that, but it's worth mentioning.


I actually discovered this problem myself just now, and searching for a fix lead me to this question. It's a very exasperating situation, and I don't understand why it works like that. You would think that disabling it would simply prevent WordPress from adding its own <p> elements—but no. It seems like it tries to prevent <p> elements, period—even yours.

If someone else has another way to go about dealing with this, I'd love to know. Silver's tips seem helpful to know though.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!