wp_get_attachment_image_src filter-hookWP 4.3.0

Filters the attachment image source result.

Usage

add_filter( 'wp_get_attachment_image_src', 'wp_kama_get_attachment_image_src_filter', 10, 4 );

/**
 * Function for `wp_get_attachment_image_src` filter-hook.
 * 
 * @param array|false  $image         Array of image data, or boolean false if no image is available.
 * @param int          $attachment_id Image attachment ID.
 * @param string|int[] $size          Requested image size. Can be any registered image size name, or an array of width and height values in pixels (in that order).
 * @param bool         $icon          Whether the image should be treated as an icon.
 *
 * @return array|false
 */
function wp_kama_get_attachment_image_src_filter( $image, $attachment_id, $size, $icon ){

	// filter...
	return $image;
}
$image(array|false)

Array of image data, or boolean false if no image is available.

  • 0(string)
    Image source URL.

  • 1(int)
    Image width in pixels.

  • 2(int)
    Image height in pixels.

  • 3(true|false)
    Whether the image is a resized image.
$attachment_id(int)
Image attachment ID.
$size(string|int[])
Requested image size. Can be any registered image size name, or an array of width and height values in pixels (in that order).
$icon(true|false)
Whether the image should be treated as an icon.

Changelog

Since 4.3.0 Introduced.

Where the hook is called

wp_get_attachment_image_src()
wp_get_attachment_image_src
wp-includes/media.php 1019
return apply_filters( 'wp_get_attachment_image_src', $image, $attachment_id, $size, $icon );

Where the hook is used in WordPress

wp-includes/blocks/site-logo.php 24
add_filter( 'wp_get_attachment_image_src', $adjust_width_height_filter );
wp-includes/blocks/site-logo.php 28
remove_filter( 'wp_get_attachment_image_src', $adjust_width_height_filter );