(字符) $image = function wp_get_attachment_image_src($attachment_id, $size='thumbnail', $icon = false);


Returns an ordered array with values corresponding to the (0) url, (1) width, (2) height, and (3) scale of an image attachment (or an icon representing any attachment).

It's most often used to get the URL (src) for an image attachment: use the first element in the returned array.

wp_get_attachment_image() uses wp_get_attachment_image_src() to fill the width, height, and src attributes of an img.

wp_get_attachment_image_src() 描述


 <?php wp_get_attachment_image_src$attachment_id$size$icon ); ?> 

wp_get_attachment_image_src() 用法



(integer) (必填) ID of the desired attachment.

默认值: None


(string/array) (可选) Size of the image shown for an image attachment: either a string keyword (thumbnail, medium, large, or full), or a 2-item array representing width and height in pixels, e.g., array(32,32). As of Version 2.5, this parameter does not affect the size of media icons, which are always shown at their original size.

默认值: thumbnail


(bool) (可选) Use a media icon to represent the attachment.

默认值: false

wp_get_attachment_image_src() 参数


Default Usage

Change Icon Directory

WordPress can use media icons to represent attachment files on your blog and in the Admin interface, if those icons are available. For images, it returns the thumbnail. For other media types, it looks for image files named by media type (e.g., audio.jpg) in the directory: wp-includes/images/crystal/.

This example shows how you can change this directory to a folder called "images" in your theme: wp-content/themes/yourtheme/images. Create the folder and put "media type images" in there. To tell WordPress the directory has changed, put this in the current theme's functions.php file:

Show the first image of the post

find the full code here get_children().

wp_get_attachment_image_src() 示例


添加于 版本: 2.5.0

wp_get_attachment_image_src() 历史


wp_get_attachment_image_src() 函数的代码位于 wp-includes/media.php.

wp_get_attachment_image_src() 源文件