投稿日:2022/03/04
WPに入れ込んだ後だけ、スライドなど画像比率がおかしくなり、
該当の画像に効いているcssが下記の内容だった場合の対処法です。
/wp-includes/css/dist/block-library/style.min.css?ver=5.9.1
themeファイルには読み込まないようにする記述を追記してありますが、それより前に制作されたものは都度追記が必要です。
__setting.php
該当の画像に効いているcssが下記の内容だった場合の対処法です。
/wp-includes/css/dist/block-library/style.min.css?ver=5.9.1
html :where(img) {
height: auto;
max-width: 100%;
}
これはWordPress5から追加されたGutenberg用のCSSのようです。themeファイルには読み込まないようにする記述を追記してありますが、それより前に制作されたものは都度追記が必要です。
__setting.php
// Gutenberg用CSSを削除する
function dequeue_plugins_style() {
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
if (is_plugin_active('classic-editor/classic-editor.php')) {
wp_dequeue_style('wp-block-library');
}
}
add_action( 'wp_enqueue_scripts', 'dequeue_plugins_style', 9999);
Gutenbergを使用していないとき、つまりClassic Editorが有効な時だけ読み込まないようになっています。