function wp_get_attachment_image_src($attachment_id, $size='thumbnail', $icon = false) {}

Retrieve an image to represent an attachment.
A mime icon for files, thumbnail or intermediate size for images.


  • int $attachment_id: Image attachment ID.
  • string $size: Optional, default is ‘thumbnail’.
  • bool $icon: Optional, default is false. Whether it is an icon.

Return values

returns:Returns an array (url, width, height), or false, if no image is available.

Defined filters

  • icon_dir
    apply_filters( 'icon_dir', ABSPATH . WPINC . '/images/crystal' )

Source code

function wp_get_attachment_image_src($attachment_id, $size='thumbnail', $icon = false) {

	// get a thumbnail or intermediate image if there is one

	if ( $image = image_downsize($attachment_id, $size) )

		return $image;

	$src = false;

	if ( $icon && $src = wp_mime_type_icon($attachment_id) ) {

		$icon_dir = apply_filters( 'icon_dir', ABSPATH . WPINC . '/images/crystal' );

		$src_file = $icon_dir . '/' . wp_basename($src);

		@list($width, $height) = getimagesize($src_file);


	if ( $src && $width && $height )

		return array( $src, $width, $height );

	return false;



No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: