问题描述
在后端进行换行时,WordPress会通过添加<p> </p>
来实现此目的.
Wordpress does this thing with adding <p> </p>
when doing a line-break in the backend.
我想知道是否可以通过jquery选择那些p
.
I wonder if it is possible to select those p
's somehow with jquery.
我猜empty()
不起作用,因为它不是真的为空,但包含
.但是contains()
可能也不起作用,因为很多其他段落也包含空格,对吧?
I guess empty()
wouldn't work since it isn't really empty but contains a
. But contains()
wouldn't probably work either since a lot of other paragraphs also contain a space, right?
我只想选择仅具有此 "的那些paragpah内部.
I only want to select those paragpahs that have only this " " inside.
更新
我应该提到我不想删除p
,而是要向其中添加一个类.
I should have mentioned that I don't want to remove the p
s but add a class to it.
推荐答案
如果可以访问主题文件,请将其添加到functions.php
文件中.
Add this to your functions.php
file if you have access to the theme files.
function user_content_replace($content) {
return str_replace('<p> </p>','<p class="example"> </p>',$content);
}
add_filter('the_content','user_content_replace', 99);
我让它插入一个类而不是删除它.
I made it insert a class instead of removing.
这篇关于jQuery:选择仅包含“& nbsp;"的段落的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!