0
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 1 year has passed since last update.

画像サイズの追加する時の仕様

Posted at

ワードプレスで、画像サイズを追加しました。その過程で、色々発見したことがあるので、メモしておく。

画像サイズの登録

add_image_size('works', 1280, 720, true);
// 先に追加したい画像サイズを登録する。

画像サイズを追加する順番は時は先にfunctions.phpに欲しい画像サイズを記述します。その後に画像をアップロードします。順番が逆になると、画像サイズが登録されないので、注意。

高さを自動で決める

add_image_size('works', 720, 0, true);

上のように画像のサイズ登録する時に高さを0にすると、横幅に応じて元の画像の縦横比を維持したまま高さが自動で決まる。逆に横幅だけを0にすると、指定された高さに応じて、横幅が自動で決まる。

画像の自動リサイズ

画像をアップロードする時に2560px以上の画像をアップロードしようとするとファイル名の語尾に-slaledがついて自動でリサイズされます。防ぐには以下のコードをfunctions.phpに追加します。

add_filter( 'big_image_size_threshold', '__return_false' );

サーバー側に負荷をかけないための仕様みたい。

参考

0
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
0
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?