Filter hook 'wp_get_attachment_image_attributes'

in WP Core File wp-includes/media.php at line 1168

View Source

wp_get_attachment_image_attributes

Filter Hook
Description
Filters the list of attachment image attributes.

Hook Information

File Location wp-includes/media.php View on GitHub
Hook Type Filter
Line Number 1168

Hook Parameters

Type Name Description
string[] $attr Array of attribute values for the image markup, keyed by attribute name. See wp_get_attachment_image().
WP_Post $attachment Image attachment post.
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).

Usage Examples

Basic Usage
<?php
// Hook into wp_get_attachment_image_attributes
add_filter('wp_get_attachment_image_attributes', 'my_custom_filter', 10, 3);

function my_custom_filter($attr, $attachment, $size) {
    // Your custom filtering logic here
    return $attr;
}

Source Code Context

wp-includes/media.php:1168 - How this hook is used in WordPress core
<?php
1163  		 *                                 See wp_get_attachment_image().
1164  		 * @param WP_Post      $attachment Image attachment post.
1165  		 * @param string|int[] $size       Requested image size. Can be any registered image size name, or
1166  		 *                                 an array of width and height values in pixels (in that order).
1167  		 */
1168  		$attr = apply_filters( 'wp_get_attachment_image_attributes', $attr, $attachment, $size );
1169  
1170  		if ( isset( $attr['height'] ) && is_numeric( $attr['height'] ) ) {
1171  			$height = absint( $attr['height'] );
1172  		}
1173  		if ( isset( $attr['width'] ) && is_numeric( $attr['width'] ) ) {

PHP Documentation

<?php
/**
		 * Filters the list of attachment image attributes.
		 *
		 * @since 2.8.0
		 *
		 * @param string[]     $attr       Array of attribute values for the image markup, keyed by attribute name.
		 *                                 See wp_get_attachment_image().
		 * @param WP_Post      $attachment Image attachment post.
		 * @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).
		 */
Quick Info
  • Hook Type: Filter
  • Parameters: 3
  • File: wp-includes/media.php
Related Hooks

Related hooks will be displayed here in future updates.