WP HOOKS
filtrod 2.8.0

wp_get_attachment_image_attributes

Args 3Plik wp-includes/media.phpDokumentacja WP ↗

Opis

Modyfikuje atrybuty tagu <img> generowanego przez wp_get_attachment_image().

Przykład użycia

add_filter( 'wp_get_attachment_image_attributes', ... )php
add_filter( 'wp_get_attachment_image_attributes', 'wpdocs_image_attrs', 10, 3 );

function wpdocs_image_attrs( $attr, $attachment, $size ) {
	$attr['data-caption'] = get_post_field( 'post_excerpt', $attachment->ID );
	return $attr;
}

Parametry

ParametrTypOpis
$attrstring[]Array of attribute values for the image markup, keyed by attribute name. See wp_get_attachment_image().
$attachment\WP_PostImage attachment post.
$sizestring | int[]Requested image size. Can be any registered image size name, or an array of width and height values in pixels (in that order).

Wywołanie

Rejestracja callbackaphp
// rejestracja funkcji zwrotnej — podaj liczbę argumentów!
add_filter( 'wp_get_attachment_image_attributes', 'twoja_funkcja', 10, 3 );

function twoja_funkcja($param_1, $param_2, $param_3) {
	// Twój kod
}

Popularne w tej kategorii