add_image_size

函式
add_image_size ( $name, $width = 0, $height = 0, $crop = false )
引數
  • (string) $name Image size identifier.
    Required:
  • (int) $width Optional. Image width in pixels. Default 0.
    Required:
  • (int) $height Optional. Image height in pixels. Default 0.
    Required:
  • (bool|array) $crop 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'.
    Required:
    Default: false
定義位置
相關方法
has_image_sizeimage_resizeremove_image_sizeimage_downsizewp_getimagesize
引入
2.9.0
棄用
-

add_image_size: 這個函式用於在WordPress中新增一個新的自定義圖片尺寸: 該函式有四個引數:圖片尺寸名稱,寬度,高度,以及圖片是否應該被裁剪。

註冊一個新的影象尺寸。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function add_image_size( $name, $width = 0, $height = 0, $crop = false ) {
global $_wp_additional_image_sizes;
$_wp_additional_image_sizes[ $name ] = array(
'width' => absint( $width ),
'height' => absint( $height ),
'crop' => $crop,
);
}
function add_image_size( $name, $width = 0, $height = 0, $crop = false ) { global $_wp_additional_image_sizes; $_wp_additional_image_sizes[ $name ] = array( 'width' => absint( $width ), 'height' => absint( $height ), 'crop' => $crop, ); }
function add_image_size( $name, $width = 0, $height = 0, $crop = false ) {
	global $_wp_additional_image_sizes;

	$_wp_additional_image_sizes[ $name ] = array(
		'width'  => absint( $width ),
		'height' => absint( $height ),
		'crop'   => $crop,
	);
}

常見問題

FAQs
檢視更多 >