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。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
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;
}
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; }
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
檢視更多 >