1. 主页
  2. 文档
  3. WordPress函数
  4. add_image_size

add_image_size

链接:https://developer.wordpress.org/reference/functions/the_custom_logo/

Register a new image size.

语法:add_image_size( string $name, int $width, int $height, bool|array $crop = false )

参数

$name
(string) (Required) Image size identifier.
要设置的缩略图名称,可接受 ‘large’,’medium’等
(int) (Optional) Image width in pixels. Default 0.
设定的最大宽度
(int) (Optional) Image height in pixels. Default 0.
设定的最大高度
(bool|array) (Optional) Image cropping behavior. If false, the image will be scaled (default), If true, image will be cropped to the specified dimensions using center positions. If an array, the image will be cropped using the array to specify the crop location. Array values must be in the format: array( x_crop_position, y_crop_position ) where:
x_crop_position accepts: ‘left’, ‘center’, or ‘right’.
y_crop_position accepts: ‘top’, ‘center’, or ‘bottom’.

Default value: false
是否切割,如果设置为true而且图片比例不能跟你设置的同比例缩放就强制切割。

使用

在你的主题目录下functions.php中加入下面的代码即可,尺寸可自由修改。

add_image_size(‘large’,630,630);//大缩略图尺寸

add_image_size(‘medium’,300,300);//中缩略图尺寸

这篇文章对您有用吗?

我们要如何帮助您?