🐡
global-style-inline-cssから`:root :where(p)`を削除したい
前提や背景
- WordPress 6.6以降
- かなり古いクラシックテーマに
theme.json
を導入した -
settings.typography.fontSizes
を利用している-
settings.typography.defaultFontSize
はfalse
-
style#global-style-inline-css
に以下のような「詳細度0のセレクタのCSS」が出力される。
:root :where(p) {
font-size: 1rem;
line-height: 1.6;
}
次のようなCSSをテーマで使っている場合、前述のインラインCSSにプロパティが上書きされてしまう。
body {
font: inherit;
line-height: 1; /* この指定の存在を前提にしている */
}
.hoge__title {
font-size: 2rem;
/* :root :where(p) の line-height: 1.6が当たってしまう。本当に適用したいline-heightは1 */
}
仕組み
-
style#global-style-line-css
には、:root :where(セレクタ)
(詳細度0のセレクタ)が出力される - ユーザーテーマの
theme.json
は、wordpress/gutenberg
のデフォルトtheme.json
を上書きしている
考察と結果
ブロックのデフォルトの設定が出力されているのでは?と判断。
テーマのtheme.json
でcore/paragraph
のブロックスタイルからtypography
の設定を明示的に空にした。
{
"settings": {
"blocks": {
"core/paragraph": {
"typography": {
"fontSizes": []
}
}
}
}
}
結果、p要素向けの詳細度0のセレクタは出力されなくなった。
Discussion