1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

wordpress5.7で、中身がスペースのみのpタグが発生し余計な余白ができる現象に対処

Posted at

Wordpressを5.7に更新すると、文節の間の余白がやたら大きく出るように。
どうも余計なpタグが発生している。
しかも内部に  。(空のpタグもある。)
エディタの方にはないのになぜ。。

空のpタグはcssで、スペース入りのものはjsで対処。

scss
// 	wordpress5.7での余白対応。
p:empty::before{
	content: "";
}
javascript
// wordpress5.7で発生したスペースのみのpタグを削除する。
// IE対応のため、forEachではなくforを使用する。
const paragraphs = document.querySelectorAll('.entry-content p')
for (let ii = 0; ii < paragraphs.length; ii++) {
	if (paragraphs[ii].innerHTML === "&nbsp;"){
		paragraphs[ii].remove()
	}
}

参考

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?