wp_get_attachment_image_url

函数
wp_get_attachment_image_url ( $attachment_id, $size = 'thumbnail', $icon = false )
参数
  • (int) $attachment_id Image attachment ID.
    Required:
  • (string|int[]) $size Optional. Image size. Accepts any registered image size name, or an array of width and height values in pixels (in that order). Default 'thumbnail'.
    Required:
    Default: 'thumbnail'
  • (bool) $icon Optional. Whether the image should be treated as an icon. Default false.
    Required:
    Default: false
返回值
  • (string|false) Attachment URL or false if no image is available. If `$size` does not match any registered image size, the original image URL will be returned.
定义位置
相关方法
wp_get_attachment_image_srcwp_get_attachment_imagewp_get_attachment_urlwp_get_attachment_image_srcsetwp_get_attachment_image_sizes
引入
4.4.0
弃用
-

wp_get_attachment_image_url: 这个函数检索一个附件图像的URL。它把附件ID作为第一个参数,还有一个可选的图片尺寸参数。如果没有指定尺寸,它会返回全尺寸的图像URL。

获得图像附件的URL。

function wp_get_attachment_image_url( $attachment_id, $size = 'thumbnail', $icon = false ) {
	$image = wp_get_attachment_image_src( $attachment_id, $size, $icon );
	return isset( $image[0] ) ? $image[0] : false;
}

常见问题

FAQs
查看更多 >