Last active
December 27, 2018 07:05
-
-
Save kurozumi/853a0aa9c75633d34813db8012ed2941 to your computer and use it in GitHub Desktop.
【WordPress】画像サイズを登録する
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* アイキャッチ画像を有効化 | |
*/ | |
add_theme_support('post-thumbnails'); | |
/* | |
* 画像サイズ登録 | |
* [width, height, [true|false|array]] | |
* | |
* 3番目の値について | |
* ・trueはセンターでトリミング | |
* ・falseはトリミングしない | |
* ・配列の場合、[x, y]で指定可能。xは[left|right]、yは[top|bottom] | |
*/ | |
$sizes = [ | |
[100, 100, true], | |
[200, 200, false], | |
[300, 300, ["center", "top"]], // センター・上寄せ | |
[400, 400, ["left", "bottom"]], // 左寄せ・下寄せ | |
]; | |
foreach ($sizes as $size) { | |
add_image_size(sprintf("%dx%d", $size[0], $size[1]), $size[0], $size[1], $size[2]); | |
add_image_size(sprintf("%dx%d@2x", $size[0], $size[1]), $size[0] * 2, $size[1] * 2, $size[2]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment