Outil de recherche WordPress pour les développeurs et auteurs de thèmes



wp_get_attachment_image_srcset ›

Depuis4.4.0
Dépréciéen/a
wp_get_attachment_image_srcset ( $attachment_id, $size = 'medium', $image_meta = null )
Paramètres: (3)
  • (int) $attachment_id Image attachment ID.
    Requis: Oui
  • (array|string) $size Optional. Image size. Accepts any valid image size, or an array of width and height values in pixels (in that order). Default 'medium'.
    Requis: Non
    Défaut: 'medium'
  • (array) $image_meta Optional. The image meta data as returned by 'wp_get_attachment_metadata()'. Default null.
    Requis: Non
    Défaut: null
Voir:
Retourne:
  • (string|bool) A 'srcset' value string or false.
Défini(e) dans:
Codex:

Retrieves the value for an image attachment's 'srcset' attribute.



Source

function wp_get_attachment_image_srcset( $attachment_id, $size = 'medium', $image_meta = null ) {
	$image = wp_get_attachment_image_src( $attachment_id, $size );

	if ( ! $image ) {
		return false;
	}

	if ( ! is_array( $image_meta ) ) {
		$image_meta = wp_get_attachment_metadata( $attachment_id );
	}

	$image_src  = $image[0];
	$size_array = array(
		absint( $image[1] ),
		absint( $image[2] ),
	);

	return wp_calculate_image_srcset( $size_array, $image_src, $image_meta, $attachment_id );
}