wpseek.com
Eine auf WordPress spezialiserte Suchmaschine für Entwickler und Theme-Autoren



wp_img_tag_add_srcset_and_sizes_attr › WordPress Function

Seit5.5.0
Veraltetn/v
wp_img_tag_add_srcset_and_sizes_attr ( $image, $context, $attachment_id )
Parameter: (3)
  • (string) $image The HTML `img` tag where the attribute should be added.
    Erforderlich: Ja
  • (string) $context Additional context to pass to the filters.
    Erforderlich: Ja
  • (int) $attachment_id Image attachment ID.
    Erforderlich: Ja
Gibt zurück:
  • (string) Converted 'img' element with 'loading' attribute added.
Definiert in:
Codex:

Adds `srcset` and `sizes` attributes to an existing `img` HTML tag.



Quellcode

function wp_img_tag_add_srcset_and_sizes_attr( $image, $context, $attachment_id ) {
	/**
	 * Filters whether to add the `srcset` and `sizes` HTML attributes to the img tag. Default `true`.
	 *
	 * Returning anything else than `true` will not add the attributes.
	 *
	 * @since 5.5.0
	 *
	 * @param bool   $value         The filtered value, defaults to `true`.
	 * @param string $image         The HTML `img` tag where the attribute should be added.
	 * @param string $context       Additional context about how the function was called or where the img tag is.
	 * @param int    $attachment_id The image attachment ID.
	 */
	$add = apply_filters( 'wp_img_tag_add_srcset_and_sizes_attr', true, $image, $context, $attachment_id );

	if ( true === $add ) {
		$image_meta = wp_get_attachment_metadata( $attachment_id );
		return wp_image_add_srcset_and_sizes( $image, $image_meta, $attachment_id );
	}

	return $image;
}